Advertisement
Advertisement


I ran into a merge conflict. How can I abort the merge?


Question

I used git pull and had a merge conflict:

unmerged:   _widget.html.erb

You are in the middle of a conflicted merge.

I know that the other version of the file is good and that mine is bad so all my changes should be abandoned. How can I do this?

2020/02/21
1
2603
2/21/2020 4:22:21 PM


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.

2016/01/19

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

2015/07/16

Its so simple.

git merge --abort

Git itself shows you the solution when you are in this type of trouble and run the git status command.

git status

Hope this will help people.

2018/12/24

I think it's git reset you need.

Beware that git revert means something very different to, say, svn revert - in Subversion the revert will discard your (uncommitted) changes, returning the file to the current version from the repository, whereas git revert "undoes" a commit.

git reset should do the equivalent of svn revert, that is, discard your unwanted changes.

2011/05/30

For scenario like, I did git fetch and git pull, then realized that upstream branch was not master branch, which resulted in unwanted conflicts.

git reset --merge 

This reverted back without resetting my local changes.

2020/02/10

Source: https://stackoverflow.com/questions/101752
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]