I ran into a merge conflict. How can I abort the merge?
I used git pull
and had a merge conflict. I know that the other version of the file is good and that mine is bad so all my changes should be abandoned. How do I do this?
unmerged: _widget.html.erb
You are in the middle of a conflicted merge.
Since your pull
was unsuccessful then HEAD
(not HEAD^
) is the last "valid" commit on your branch:
git reset --hard HEAD
The other piece you want is to let their changes over-ride your changes.
Older versions of git allowed you to use the "theirs" merge strategy:
git pull --strategy=theirs remote_branch
But this has since been removed, as explained in this message by Junio Hamano (the Git maintainer). As noted in the link, instead you would do this:
git fetch origin
git reset --hard origin
If your git version is >= 1.6.1, you can use git reset --merge
.
Also, as @Michael Johnson mentions, if your git version is >= 1.7.4, you can also use git merge --abort
.
As always, make sure you have no uncommitted changes before you start a merge.
From the git merge man page
git merge --abort
is equivalent to git reset --merge
when MERGE_HEAD
is present.
MERGE_HEAD
is present when a merge is in progress.
Also, regarding uncommitted changes when starting a merge:
If you have changes you don't want to commit before starting a merge, just git stash
them before the merge and git stash pop
after finishing the merge or aborting it.
git merge --abort
Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
If there were uncommitted worktree changes present when the merge started, git merge --abort
will in some cases be unable to reconstruct these changes. It is therefore recommended to always commit or stash your changes before running git merge.
git merge --abort
is equivalent to git reset --merge
when MERGE_HEAD
is present.
http://www.git-scm.com/docs/git-merge
链接地址: http://www.djcxy.com/p/1112.html上一篇: Internet Explorer 9可以使用多长时间的URL?
下一篇: 我遇到了合并冲突。 我如何中止合并?