Skip to content
Fix Code Error

How to revert a merge commit that’s already pushed to remote branch?

March 13, 2021 by Code Error
Posted By: Anonymous

git revert <commit_hash> alone won’t work. -m must be specified, and I’m pretty confused about it.

Anyone experienced this before?

Solution

The -m option specifies the parent number. This is because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.

When you view a merge commit in the output of git log, you will see its parents listed on the line that begins with Merge:

commit 8f937c683929b08379097828c8a04350b9b8e183
Merge: 8989ee0 7c6b236
Author: Ben James <[email protected]>
Date:   Wed Aug 17 22:49:41 2011 +0100

Merge branch 'gh-pages'

Conflicts:
    README

In this situation, git revert 8f937c6 -m 1 will get you the tree as it was in 8989ee0, and git revert -m 2 will reinstate the tree as it was in 7c6b236.

To better understand the parent IDs, you can run:

git log 8989ee0 

and

git log 7c6b236
Answered By: Anonymous

Related Articles

  • Form field border-radius is not working only on the last…
  • Trouble with boxes appearing/hiding based on selection
  • Why google charts is giving different output for candlestick…
  • 'block in draw' rails 6 routes
  • Why call git branch --unset-upstream to fixup?
  • Why do I have to "git push --set-upstream origin "?
  • Why do git fetch origin and git fetch : behave differently?
  • Generating a drop down list of timezones with PHP
  • Difference between git checkout --track origin/branch and…
  • Git - Pushing code to two remotes

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Copy all the lines to clipboard

Next Post:

Turning off eslint rule for a specific line

Leave a Reply Cancel reply

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

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error