如何撤消存在冲突的 git 合并
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5741407/
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
How to undo a git merge with conflicts
提问by Anshul
I am on branch mybranch1
. mybranch2
is forked from mybranch1
and changes were made in mybranch2
.
我在分支上mybranch1
。mybranch2
分叉自mybranch1
并在 中进行了更改mybranch2
。
Then, while on mybranch1
, I have done git merge --no-commit mybranch2
It shows there were conflicts while merging.
然后,在mybranch1
,我已经完成了git merge --no-commit mybranch2
它表明合并时存在冲突。
Now I want do discard everything (the merge
command) so that mybranch1
is back to what it was before.
I have no idea how do I go about this.
现在我想丢弃所有内容(merge
命令),以便mybranch1
恢复到以前的状态。我不知道我该怎么做。
回答by Daniel Cassidy
Latest Git:
最新的 Git:
git merge --abort
This attempts to reset your working copy to whatever state it was in before the merge. That means that it should restore any uncommitted changes from before the merge, although it cannot always do so reliably. Generally you shouldn't merge with uncommitted changes anyway.
这会尝试将您的工作副本重置为合并之前的任何状态。这意味着它应该从合并之前恢复任何未提交的更改,尽管它不能总是可靠地这样做。通常,您无论如何都不应该合并未提交的更改。
Prior to version 1.7.4:
1.7.4 版之前:
git reset --merge
This is older syntax but does the same as the above.
这是较旧的语法,但与上述语法相同。
Prior to version 1.6.2:
1.6.2 之前的版本:
git reset --hard
which removes all uncommitted changes, including the uncommitted merge. Sometimes this behaviour is useful even in newer versions of Git that support the above commands.
这将删除所有未提交的更改,包括未提交的合并。有时,即使在支持上述命令的较新版本的 Git 中,这种行为也很有用。
回答by Martin G
Actually, it is worth noticing that git merge --abort
is only equivalent to git reset --merge
given that MERGE_HEAD
is present. This can be read in the git help for merge command.
实际上,值得注意的git merge --abort
是,仅相当于给git reset --merge
定MERGE_HEAD
存在。这可以在合并命令的 git 帮助中阅读。
git merge --abort # is equivalent to git reset --merge when MERGE_HEAD is present.
After a failed merge, when there is no MERGE_HEAD
, the failed merge can be undone with git reset --merge
but not necessarily with git merge --abort
, so they are not only old and new syntax for the same thing.
合并失败后,如果没有MERGE_HEAD
,失败的合并可以用 撤消,git reset --merge
但不一定用git merge --abort
,因此它们不仅是同一事物的新旧语法。
Personally I find git reset --merge
much more useful in everyday work.
我个人觉得git reset --merge
在日常工作中更有用。
回答by Adam Dymitruk
Assuming you are using the latest git,
假设您使用的是最新的 git,
git merge --abort
回答by Manish Kumar Singh
There are two things you can do first undo merge by command
有两件事你可以先通过命令撤消合并
git merge --abort
or
或者
you can go to your previous commit state temporarily by command
你可以通过命令临时进入你之前的提交状态
git checkout 0d1d7fc32
回答by Kamil Kie?czewski
Sourcetree
源码树
If you not commit your merge, then just double click on another branch (=checkout) and when sourcetree ask you about discarding all changes then agree
如果您不提交合并,则只需双击另一个分支(= checkout),当 sourcetree 询问您是否放弃所有更改时,请同意