Git:错误合并,然后恢复合并。现在不能再次合并分支 [英] Git: Wrong Merge, then reverted the merge. Now not able to merge the branch again
问题描述
这是我做的。
- 我将最新的主人合并到我的分支并推送它
- 后来意识到此合并已损坏并恢复合并
- 现在
我可以知道如何强制合并所有更改高手给我的分支?
预先感谢。
假设您的功能分支功能
和 master
开始如下所示:
master:A - > B - > C
功能:A - > D
合并 master
是什么样子:
master:A - > B - > C
功能:A - > D - > M#M是一个合并提交
接下来你的还原了中的合并特性
通过执行 git revert
分支。这意味着你告诉Git添加一个新的提交来撤消合并的结果。现在,这是两个分支的状态:
master:A - > B - > C
功能:A - > D - > M - > R#R是一个回复提交
当您尝试将 master
转换为
特性
,Git告诉你,你已经是最新的了,因为你是!在合并过程中,无论发生什么事情,恢复提交功能都没有问题,但是现在在功能
分支中有两个新提交。
要回到您在特性
分支中进行错误合并之前所处的状态,可以在中分支两次合并和还原提交,特征
。完全按照以下步骤操作:
git checkout功能#切换到您的功能分支
git reset --hard HEAD〜2 #核实'M'和'R'提交
在此之后,您可以尝试与 master
再次,所有都应该没问题。请注意,这个选项涉及 的历史记录。 功能
分支,通过nuking提交,并且如果分支是共享的和,则可能不应使用您已使用合并提交推送分支。如果您属于此类别,请参阅@torek提供的其他选项的答案。
I'm in a little trouble with git.
Here is what i did.
- I merged latest master to my branch and pushed it
- Later realised that this merge is corrupted and reverted the merge
- Now I'm trying to merge master again, it says its up to date.
Can I know how I can force merge all the changes of master to my branch?
Thanks in advance.
Let's say that your feature branch feature
and master
started off like this:
master: A -> B -> C
feature: A -> D
After merging master
into feature, this is how things looked:
master: A -> B -> C
feature: A -> D -> M # M is a merge commit
Next your reverted the merge in the feature
branch by doing a git revert
. This means that you told Git to add a new commit to undo the result of the merge. Now this is the state of the two branches:
master: A -> B -> C
feature: A -> D -> M -> R # R is a revert commit
When you try to pull master
into feature
, Git is telling you that you are already up to date, because you are! The revert commit functionally undid whatever happened during the merge, but now you have two new commits in your feature
branch.
To get back to the state you were in before you made the erroneous merge in your feature
branch, you can nuke the two merge and revert commits in feature
. Follow these steps exactly:
git checkout feature # switch to your feature branch
git reset --hard HEAD~2 # nuke the 'M' and 'R' commits
After this, you can try doing a merge with master
again and all should be fine. Of course, make sure that you do the merge properly.
Note that this option involves rewriting the history of the feature
branch, via nuking commits, and should probably not be used if the branch is shared and you have already pushed the branch with the merge commit. See the answer by @torek for other options if you fall into this category.
这篇关于Git:错误合并,然后恢复合并。现在不能再次合并分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!