Skip to content

Instantly share code, notes, and snippets.

@omarrodriguez15
Created February 13, 2020 16:00
Show Gist options
  • Select an option

  • Save omarrodriguez15/ec14b0cba8a58c7b353eef53e5e7bc39 to your computer and use it in GitHub Desktop.

Select an option

Save omarrodriguez15/ec14b0cba8a58c7b353eef53e5e7bc39 to your computer and use it in GitHub Desktop.
Reverts a git merge commit

Find the merge commit you want to revert

Look at the git log using git log --graph. In the commit message look at the Merge: section to check to see which parent tree you want to keep in the revert. Example commit message: (This was a commit from a feature branch into develop branch. develop branch is on the right 7c6b236 develop on the left 8989ee0)

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

The git command

To perform the revert execute the following:

git revert 8f937c6 -m 1

8f937c6 indicates the merge commit we want to revert. -m option specifies the parent number. This is necessary to specify when reverting a merge commit because a merge commit has more than one parent. 1 indicates the tree 8989ee0.

More info on this SO answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment