Git 将分支合并到 master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14605231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:23:16  来源:igfitidea点击:

Git merge branch into master

gitgit-branchgit-merge

提问by Trt Trt

I have a master branch and a working branch_1. I want to 'move' branch_1exactly as it is to master. So I want something like this:

我有一个 master 分支和一个工作branch_1. 我想branch_1完全“移动”到master. 所以我想要这样的东西:

git checkout master
git merge branch_1 # I don't know what is correct...

Things which I did but I got loads of files messed up with annoying conflicts. So now master contains exactly the same files of branch_1avoiding any conflicts, just overwriting files. Any help?

我做了一些事情,但我得到了大量文件,这些文件被烦人的冲突弄得一团糟。所以现在 master 包含完全相同的文件,branch_1避免任何冲突,只是覆盖文件。有什么帮助吗?

回答by Schleis

Conflicts are going to happen if both branches have changes to the files. This is a good thing. Keeping your branches up-to-date with each other will prevent some of them. However over all, conflicts are not bad. The rebase option can also prevent many of them from happening.

如果两个分支都对文件进行了更改,则会发生冲突。这是一件好事。 使您的分支机构彼此保持最新状态将阻止其中的一些。但总的来说,冲突并不坏。rebase 选项还可以防止其中许多情况发生。

git merge branch_1

If you are on master, merging will bring the changes as you expect.

如果您打开master,合并将带来您期望的更改。

http://www.kernel.org/pub/software/scm/git/docs/git-merge.html

http://www.kernel.org/pub/software/scm/git/docs/git-merge.html

You could also

你也可以

git rebase branch_1

This will take the changes from branch_1and append them to master without a merge commit.

这将在branch_1没有合并提交的情况下获取更改并将它们附加到 master。

http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html

http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html

回答by sjas

Maybe you should not merge?

也许你不应该合并?

  1. Checkout branch_1
  2. Rebase master changes into branch_1
  3. Fix any errors that might have occured after testing your code
  4. Checkout master
  5. Rebase branch_1 changes into master
  1. 结帐分支_1
  2. 将 master 更改重新设置为 branch_1
  3. 修复测试代码后可能发生的任何错误
  4. 结账师傅
  5. 将 branch_1 更改变基为 master

or in code:

或在代码中:

git checkout branch_1
git rebase master
(...)
git checkout master
git rebase branch_1

This also gives you the opportunity to squash several commits into one, if you want to make your changesets more dense, and prevents these annoying merge-commits in your history.

如果您想让变更集更密集,并防止这些烦人的合并提交出现在您的历史记录中,这也使您有机会将多个提交合并为一个。

回答by thisara udayantha

On the command prompt you may type 'git status'. This gives you the current branch that you are working on which is also known as the active branch at this time. Once you execute git merge branch_1, Git will merge branch_1 changes on the active branch.

在命令提示符下,您可以键入“git status”。这为您提供了您正在处理的当前分支,此时也称为活动分支。执行 git merge branch_1 后,Git 将合并活动分支上的 branch_1 更改。

Else you could try 'git merge branch_1 master' instead.

否则你可以尝试 'git merge branch_1 master' 代替。

More info about Git merge and overall : https://medium.com/@thisara.udaya/git-under-the-hood-34dbb807330c

有关 Git 合并和整体的更多信息:https: //medium.com/@thisara.udaya/git-under-the-hood-34dbb807330c