Git:错误合并,然后恢复合并。现在不能再次合并分支 [英] Git: Wrong Merge, then reverted the merge. Now not able to merge the branch again

查看:1300
本文介绍了Git:错误合并,然后恢复合并。现在不能再次合并分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我做的。


  1. 我将最新的主人合并到我的分支并推送它

  2. 后来意识到此合并已损坏并恢复合并

  3. 现在

我可以知道如何强制合并所有更改高手给我的分支?



预先感谢。

解决方案

假设您的功能分支功能 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.

  1. I merged latest master to my branch and pushed it
  2. Later realised that this merge is corrupted and reverted the merge
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆