2

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.

1

2 Answers 2

3

Try git merge --abort

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

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

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 You're right, thanks for the correction! I've edited the response to reflect this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.