1

Now I'm in a merging state. I want to discard all changes, to back to the state that before the merging, and when I do the merge again, it says "Already up-to-date". Is there a nice way to do it?

My attempt: git reset --hard head but when I do the merge again, still conflict. what I have to do is manually revert all changes by hand and do a empty commit, very tedious.

July
  • 695
  • 3
  • 9
  • 21
  • Possible duplicate of [I ran into a merge conflict. How can I abort the merge?](http://stackoverflow.com/questions/101752/i-ran-into-a-merge-conflict-how-can-i-abort-the-merge) – Sébastien Dawans Oct 20 '16 at 11:45

2 Answers2

2

Try git merge --abort

It aborts the current merge and takes you back where you were.

Matt
  • 2,749
  • 1
  • 18
  • 28
1

From what I understood you want to do a merge but, for every conflict, fallback to the version in the original branch instead of the one you are merging with.

If that's the case, tou can try using -Xours

git merge -Xours <name of your other branch>

There's also the option of falling back to the other branch's conflicted changes with -Xtheirs

For more reference, check git's advanced merging docs

fmello
  • 553
  • 2
  • 9
  • 1
    Note that `-X ours` (spelled with or without a space) takes "our" *change*, not our *file*. For instance, supposed in file `README`, we changed `color` to `colour` on line 17 while they changed `red` to `green` on the same line. These conflict, so `-X ours` keeps it as `red colour`. Meanwhile they changed line 34 to refer back to the `green dots` ... which we didn't touch, so now line 34 refers to `green dots` even though line 17 says `red colour`. – torek Oct 20 '16 at 12:08
  • @torek You're right, thanks for the correction! I've edited the response to reflect this. – fmello Oct 20 '16 at 12:59