问题
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.
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?
回答1:
as long as you did not commit you can type
git merge --abort
just as the command line suggested.
回答2:
If you do "git status" while having a merge conflict, the first thing git shows you is how to abort the merge.
回答3:
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?
https://git-scm.com/blog/2010/03/02/undoing-merges.html
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.
But honestly this guide here is better than anything I can explain, with diagrams! :)
来源:https://stackoverflow.com/questions/44048982/abort-a-git-merge