Git Merge - 不合并来自远程分支的所有更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4829964/
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
Git Merge - Not merging all changes from remote branch
提问by janegee
I branched from master and created a branch called extra_work. Then I made lots of changes to master which included removing some files as well. Later now when I tried to merge the branch 'extra_work' into the master, it is not merging it entirely. It is not adding the files that I removed in master, basically all the work that I had undone, now I want it back into my master. How do I merge these two branches so that all the extra files/work from my 'extra_work' branch merges into master. Thanks
我从 master 分支并创建了一个名为 extra_work 的分支。然后我对 master 做了很多更改,其中包括删除一些文件。稍后当我尝试将分支“extra_work”合并到主分支时,它并没有完全合并它。它不是添加我在 master 中删除的文件,基本上是我已撤消的所有工作,现在我想将它放回到我的 master 中。我如何合并这两个分支,以便我的“extra_work”分支中的所有额外文件/工作合并到 master 中。谢谢
回答by Adam
Rebase your extra_work
branch against master
. This will rewind your extra_work
branch to the state when you branched, and apply the commits from master
to extra_work
. It will then replay all the commits from extra_work
back onto itself. If you inspect git log
after that you will see the commits from master
further back in the history of the branch. You should then be able to merge to master
with no problems.
衍合extra_work
抗分支master
。这会将您的extra_work
分支回滚到您分支时的状态,并将提交应用master
到extra_work
。然后它会重放所有的提交extra_work
到它自己。如果您git log
在此之后进行检查,您将master
在分支的历史记录中看到更远的提交。然后,您应该能够毫无问题地合并到master
。
git rebase master
回答by kelloti
I ran into the same problem very recently while doing major refactoring. I solved the problem by doing git rebase
, from master
rebasing onto extra-work
. I don't fully understand this whole thing, but the merge went terribly (like you experienced) but rebasing in this particular direction was very easy. See the git book on rebasing: http://book.git-scm.com/4_rebasing.html
我最近在进行重大重构时遇到了同样的问题。我通过git rebase
从master
rebase 到extra-work
. 我不完全理解这整件事,但合并进行得非常糟糕(就像你所经历的那样),但在这个特定方向上重新定位非常容易。请参阅关于变基的 git 书:http: //book.git-scm.com/4_rebasing.html