如何取消合并 Git 合并?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28932515/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:59:10  来源:igfitidea点击:

How to unmerge a Git merge?

gitgithubmergegit-pull

提问by redAce

I accidentally did a git pull origin masterfrom dev, and master got merged into dev. Is it possible to unmerge?

我不小心做了一个git pull origin masterfrom dev,master 被合并到了 dev 中。是否可以取消合并?

I've already seen different solutions, i tried this one from both dev and master : git revert -m 1 <commit>(once each) But i got : Everything is up-to-date, each time

我已经看到了不同的解决方案,我从 dev 和 master 那里都尝试了这个:( git revert -m 1 <commit>每次一次)但我得到:每次都是最新的

I want to undo the merge master in dev : https://github.com/iliassk/PED_MyTodo/commits/devcommit:e382550

我想撤消 dev 中的合并主:https://github.com/iliassk/PED_MyTodo/commits/dev commit:e382550

回答by Andreas Wederbrand

You can reset your branch to the state it was in just before the merge if you find the commit it was on then.

如果您发现它当时处于提交状态,您可以将您的分支重置为它在合并之前的状态。

One way is to use git reflog, it will list all the HEADs you've had. I find that git reflog --relative-dateis very useful as it shows how long ago each change happened.

一种方法是使用git reflog,它会列出您拥有的所有 HEAD。我发现这git reflog --relative-date非常有用,因为它显示了每次更改发生的时间。

Once you find that commit just do a git reset --hard <commit id>and your branch will be as it was before.

一旦你发现提交只是做一个git reset --hard <commit id>,你的分支就会和以前一样。

If you have SourceTree, you can look up the <commit id>there if git reflogis too overwhelming.

如果你有SourceTree,你可以在<commit id>那里查找如果git reflog太多的话。

回答by Nikhil

If you haven't committed the merge, then use:

如果您尚未提交合并,请使用:

git merge --abort

git merge --abort

回答by poige

git revert -mallows to un-merge still keeping the history of both merge and un-do operation. Might be good for documenting probably.

git revert -m允许取消合并仍然保留合并和取消操作的历史记录。可能适合记录。