中止 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
Abort a Git Merge
提问by Salman Kazmi
I am working on a project using Git as the VCS. I got a branch xyz
cut 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
回答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: how to reverse-merge a commit?
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:
所以我想我会总结其中的一些:
git revert <merge commit hash>
This creates an extra "revert" commit saying you undid a mergegit 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 tocherry-pick
them on to afterwards.
git revert <merge commit hash>
这会创建一个额外的“还原”提交,说明您取消了合并git reset --hard <commit hash *before* the merge>
这将历史重置为您进行合并之前。如果您在合并后进行了提交,您将需要cherry-pick
在之后提交。
But honestly thisguide here is better than anything I can explain, with diagrams! :)
但老实说,这里的指南比我能用图表解释的任何东西都要好!:)