Git revert merge commit

TL;DR: git revert -m 1 <commit>

Let’s say you merged a pull request on GitHub but now need to revert it.

Find merge commit

Given you’re on latest master:

$ git checkout master
$ git pull

To find the merge commit:

$ git log --grep='Merge pull request'

Copy the commit hash, which looks something like this:


Revert on master

To revert a merge commit on master (see Stackoverflow answer):

$ git revert -m 1 <commit> # replace `<commit>` with hash

Now you can push your revert to master:

$ git push

Revert on branch

Create a branch for the revert:

$ git checkout -b revertBranch

Revert the merge commit:

$ git revert -m 1 <commit> # replace `<commit>` with hash

Push the branch up and open a pull request:

$ git push origin revertBranch

Please support this site and join our Discord!