6

I've done merge some-branch into master, but gets confilcts. How to undo this ?

git checkout master
git merge some-branch
...
CONFLICTS :(
3
  • did you try git reset --hard ?
    – phoet
    Commented Jul 10, 2012 at 8:17
  • I checked this. Works! how can I thank You?
    – marioosh
    Commented Jul 10, 2012 at 8:20
  • careful with reset --hard.. you can cut yourself with that in other cases. Commented Jul 10, 2012 at 8:20

3 Answers 3

15
git merge --abort

is a recently added option. It does what you expect.

3

If you have conflicts, your merge will not be committed yet so you can use git reset --hard HEAD to remove the merge.

1
  • 2
    do not encourage the use of git reset --hard Commented Jul 10, 2012 at 17:31
1

With modern git, you can, as suggested in previous answer:

git merge --abort

Older syntax:

git reset --merge

Old-school, also suggested in previous answer:

git reset --hard

But actually, it is worth noticing that git merge --abort is only equivalent to git reset --merge given that MERGE_HEAD is present. This can be read in the git help for merge command.

git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.

After a failed merge, when there is no MERGE_HEAD, the failed merge can be undone with git reset --merge but not necessarily with git merge --abort, so they are not only old and new syntax for the same thing.

Personally I find git reset --merge more useful in everyday work so this is the method i use all the time.

Not the answer you're looking for? Browse other questions tagged or ask your own question.