在 Git 存储库中针对 master 更新过时的分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8965781/
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
Update an outdated branch against master in a Git repo
提问by Andrew
I have a Git repository that has branch (local and remote) that has become outdated. I would like to bring this branch up to date with the master branch, but I don't know how to do this. There will also probably be many merge conflicts.
我有一个 Git 存储库,它的分支(本地和远程)已经过时了。我想让这个分支与主分支保持同步,但我不知道如何做到这一点。也可能会有很多合并冲突。
How can I bring or update this out-of-date branch to the same state as the master branch?
如何将这个过时的分支更新为与 master 分支相同的状态?
回答by Daniel Pittman
Update the master branch, which you need to do regardless.
更新 master 分支,无论如何你都需要做。
Then, one of:
然后,其中之一:
Rebase the old branch against the master branch. Solve the merge conflicts during rebase, and the result will be an up-to-date branch that merges cleanly against master.
Merge your branch into master, and resolve the merge conflicts.
Merge master into your branch, and resolve the merge conflicts. Then, merging from your branch into master should be clean.
将旧分支重新绑定到主分支。解决 rebase 期间的合并冲突,结果将是一个最新的分支,可以与 master 干净地合并。
将您的分支合并到 master 中,并解决合并冲突。
将 master 合并到您的分支中,并解决合并冲突。然后,从你的分支合并到 master 应该是干净的。
None of these is better than the other, they just have different trade-off patterns.
这些都不比另一个更好,它们只是具有不同的权衡模式。
I would use the rebase approach, which gives cleaner overall results to later readers, in my opinion, but that is nothing aside from personal taste.
我会使用 rebase 方法,在我看来,它可以为以后的读者提供更清晰的整体结果,但这与个人品味无关。
To rebase and keep the branch you would:
要重新设置并保留分支,您将:
git checkout <branch> && git rebase <target>
In your case, check out the old branch, then
在你的情况下,检查旧分支,然后
git rebase master
to get it rebuilt against master.
让它针对主人重建。