Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undoing a merge done with --no-ff

Tags:

git

undo

merge

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.

like image 351
blogofsongs Avatar asked Oct 19 '22 17:10

blogofsongs


1 Answers

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

git revert SHA_OF_MERGE_COMMIT0944694980cc3dfcf4c2f9a99c3aadbfa47811ee -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.

like image 174
Eugene Kaurov Avatar answered Oct 22 '22 21:10

Eugene Kaurov