撤消git合并 [英] Undoing a git merge

查看:118
本文介绍了撤消git合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Git并没有那么有经验,现在我有一个很大的问题陷入了我的怀抱。



以下是我当前分支的样子:

 特性/ --- F1 ----- F2 ---- \ 
/ \
master ----- M0 ----- M1 ----- M2 ----- M3 ----- M4
\ /
bugfix \ - B1 --- --B2 ----------- /

情况:

有人做了一件非常糟糕的事情,并推出了一个非常糟糕的合并(M3)。在我将B1和B2合并到M4后,我只注意到我们的模型(不是源代码)不会加载时的错误合并。幸运的是,我还没有推M4。



问题:



我如何设置正确的东西?我想要M0,M1,M2,F1,F2,B1和B2。但我不想要M3和M4(因为M4显然已经坏掉了)。如果我有放弃更改,那么可以牺牲F1和F2:)

我查看了 git revert 但我不确定我完全理解它是如何工作的。所以...我真的希望能够帮助解决这个问题。



预先致谢。

解决方案

因此,澄清,你想要的是这个,对吗?

 功能/ --F1 ----- F2 
/
主人----- M0 ----- M1 ----- M2
\
bugfix \ --B1 ----- B2

确保 HEAD s 功能 bugfix 仍在 F2 B2
$ b 编辑:if 特性 bugfix 没有分支,让它们分支(如果它未被取消,则保留你的工作):

  git checkout F2 
git分支功能
git checkout B2
git分支bugfix



编辑结束

然后将主人重置为M2:

  git checkout maste r 
git reset M2 --hard

(重置会让您失去本地更改, )



M3 M4 code>不会立即销毁,但会最终结束。它们不应该出现在 git log 或gitk中。

然后是合并功能并使 M3'无误。


I'm not that experienced with Git and now I have a big problem falling into my lap.

Here's how my current branch look like:

feature       /---F1-----F2----\
             /                  \
master -----M0-----M1-----M2-----M3-----M4
             \                        /
bugfix        \--B1-----B2-----------/

The situation:

Someone did a very bad thing and pushed a really bad merge (M3). I only noticed the bad merge when our models (not source code) wouldn't load after I merged B1 and B2 into M4. Luckily, I haven't pushed M4 yet.

The problem:

How do I set things right again? I want M0, M1, M2, F1, F2, B1, and B2. But I don't want M3 and M4 (since M4 is obviously broken). If I have to abandon changes, then F1 and F2 can be sacrificed :)

I looked at git revert but I'm not confident that I fully understand how it works. So... I'm really hoping for help on how to resolve this.

Thanks in advance.

解决方案

So to clarify, what you want is this, right?

feature       /---F1-----F2
             /                 
master -----M0-----M1-----M2
             \            
bugfix        \--B1-----B2

Make sure that the HEADs feature and bugfix are still on F2 and B2 respectively.

Edit: if feature and bugfix are no branches, make them branches (stash your work if it is uncommited):

git checkout F2
git branch feature
git checkout B2
git branch bugfix

Edit end

Then reset the master to M2:

git checkout master
git reset M2 --hard

(reset will make you lose your local changes, stash them if you don't want that.)

M3 and M4 are not destroyed right away, but will be eventually. They should not show up in git log or gitk.

Then it's time to merge feature and make a M3' that is correct.

这篇关于撤消git合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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