7

I've heard that a git merge done with the --no-ff flag preserves full history making it easier to pull out a specific merge. I've not seen it explained, though, how to undo a merge made with --no-ff. Also, I can't see how it makes it easier to unmerge than a fast-forward merge. Can someone shed some light on this, or point me to some good info on this?

Thanks.

blogofsongs
  • 2,527
  • 4
  • 21
  • 26
  • 2
    because you can `git revert SHA_OF_MERGE_COMMIT -m 1` or similar in the `--no-ff` case, if the merge was a fast forward you could have any number of commits that are included in it and you would need to revert them all potentially – Andrew C Feb 12 '15 at 21:25

1 Answers1

4

You can revert all commits made by the fast forward merge (--no-ff):

git revert SHA_OF_MERGE_COMMIT0944694980cc3d -m 1 

the most important here is a key -m 1

-m parent-number

--mainline parent-number

Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent.

Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want.

See the revert-a-faulty-merge How-To for more details.

Eugene Kaurov
  • 2,356
  • 28
  • 39