如何撤消 git merge 冲突
我在分支 mybranch1
上。 mybranch2
是从 mybranch1
分叉出来的,并在 mybranch2
中进行了更改。
然后,在 mybranch1
上,我完成了 git merge --no-commit mybranch2
这表明合并时存在冲突。
现在我想丢弃所有内容(merge
命令),以便 mybranch1
恢复到之前的状态。 我不知道该怎么办。
I am on branch mybranch1
. mybranch2
is forked from mybranch1
and changes were made in mybranch2
.
Then, while on mybranch1
, I have done git merge --no-commit mybranch2
It shows there were conflicts while merging.
Now I want to 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
最新的 Git:
这会尝试将您的工作副本重置为合并之前的状态。这意味着它应该恢复合并之前的任何未提交的更改,尽管它并不总是可靠地做到这一点。一般来说,无论如何您都不应该合并未提交的更改。
1.7.4 版本之前:
这是较旧的语法,但与上面的功能相同。
1.6.2 之前的版本:
删除所有未提交的更改,包括未提交的合并。有时,即使在支持上述命令的较新版本的 Git 中,此行为也很有用。
Latest Git:
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:
This is older syntax but does the same as the above.
Prior to version 1.6.2:
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.
实际上,值得注意的是,考虑到存在
MERGE_HEAD
,git merge --abort
仅相当于git reset --merge
。这可以在 git 合并命令帮助中阅读。合并失败后,当没有
MERGE_HEAD
时,可以使用git reset --merge
撤消失败的合并,但不一定使用git merge --abort< /code>,所以它们不仅仅是同一事物的新旧语法。
就我个人而言,我发现 git reset --merge 在日常工作中更有用。
Actually, it is worth noting that
git merge --abort
is only equivalent togit reset --merge
given thatMERGE_HEAD
is present. This can be read in the git help for merge command.After a failed merge, when there is no
MERGE_HEAD
, the failed merge can be undone withgit reset --merge
but not necessarily withgit merge --abort
, so they are not only old and new syntax for the same thing.Personally I find
git reset --merge
much more useful in everyday work.假设你使用的是最新的 git,
Assuming you are using the latest git,
如果使用最新的 Git,
否则这将在较旧的 git 版本中完成工作
,或者
If using latest Git,
else this will do the job in older git versions
or
有两件事你可以先通过命令撤消合并
,或者
你可以通过命令暂时转到之前的提交状态
There are two things you can do first undo merge by command
or
you can go to your previous commit state temporarily by command
由于之前没有人提到过这一点,如果您
在尝试上述方法时遇到此错误,您可以尝试添加文件(暂存它们),然后只需执行
git stash
即可使用- 提交,而不是提交 - m
标志并给它一个标签,这样你就知道如果你偶然需要恢复最后的状态,你可以使用git stash list
找到存储。对我来说, git reset --merge 和 git merge --abort 失败并出现上述错误。
Since nobody mentioned this before, if you get this error
when trying the above methods you can try adding the files (staging them) and then instead of committing just do
git stash
you can use the-m
flag and give it a tag so you know if you do by chance need to recover that last state you can find the stash withgit stash list
.For me,
git reset --merge
andgit merge --abort
failed with above error.Sourcetree
如果您不提交合并,则只需双击另一个分支 (=checkout),当 sourcetree 询问您是否放弃所有更改时,请同意
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