How to revert or rollback your most recent merge in git

Risky oper­a­tions like a merge can some­times leave you unhappy if the merge turned out to be too messy to clean. You can use the below com­mand to go back the the state just before your merge. NOTE: This is best used only for merges that you haven’t pushed upstream.

git reset --hard ORIG_HEAD

The ORIG_HEAD always points to the com­mit in the cur­rent branch before the merge. Although this is nice to have for a 3 way merge, a great side effect of this com­mand is that if you did a fast for­ward merge that had 10 fast for­ward­ing com­mits, you can directly go back to the com­mit that you were on just before the merge oper­a­tion by using the above com­mand. That way you dont need to count how many com­mits you want to go back in his­tory for to revert a fast for­ward merge.

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *