中止 Git 合并

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

Abort a Git Merge

gitgit-merge

提问by Salman Kazmi

I am working on a project using Git as the VCS. I got a branch xyzcut from the mainline branch of master. After working for a while, I committed my code and took a pull of the branch mainline.

我正在开发一个使用 Git 作为 VCS 的项目。我xyz从 master 的主线分支中得到了一个分支。工作了一段时间后,我提交了我的代码并拉取了分支主线。

The pull was fine. I then merged the code with master. After the merge, there were problems in certain files. I have not committed the code after merging. Can someone please guide as to how I can abort this merge and bring my branch where I am working currently to the state where it was before I merged it?

拉力很好。然后我将代码与 master 合并。合并后,某些文件存在问题。合并后我没有提交代码。有人可以指导我如何中止这次合并并将我目前工作的分支带到合并之前的状态吗?

回答by Timothy Truckle

as long as you did not commit you can type

只要你没有提交,你就可以输入

git merge --abort

just as the command line suggested.

就像命令行建议的那样。

回答by MLY

If you do "git status" while having a merge conflict, the first thing git shows you is how to abort the merge.

如果您在发生合并冲突时执行“git status”,那么 git 向您展示的第一件事就是如何中止合并。

output of git status while having a merge conflict

出现合并冲突时 git status 的输出

回答by denis.lobanov

Truth be told there are many, many resources explaining how to do this already out on the web:

说实话,网上已经有很多资源解释了如何做到这一点:

Git: how to reverse-merge a commit?

Git:如何反向合并提交?

Git: how to reverse-merge a commit?

Git:如何反向合并提交?

Undoing Merges, from Git's blog (retrieved from archive.org's Wayback Machine)

撤消合并,来自 Git 的博客(取自 archive.org 的 Wayback Machine)

So I guess I'll just summarize some of these:

所以我想我会总结其中的一些:

  1. git revert <merge commit hash>
    This creates an extra "revert" commit saying you undid a merge

  2. git reset --hard <commit hash *before* the merge>
    This reset history to before you did the merge. If you have commits after the merge you will need to cherry-pickthem on to afterwards.

  1. git revert <merge commit hash>
    这会创建一个额外的“还原”提交,说明您取消了合并

  2. git reset --hard <commit hash *before* the merge>
    这将历史重置为您进行合并之前。如果您在合并后进行了提交,您将需要cherry-pick在之后提交。

But honestly thisguide here is better than anything I can explain, with diagrams! :)

但老实说,这里的指南比我能用图表解释的任何东西都要好!:)