Git revert merge commit

TL;DR: revert merge commit <sha> with:

git revert -m 1 <sha>

How do you revert a merged pull request with Git?

Find merge commit

Given you’re on latest master:

git checkout master && git pull

Find the merge commit:

git log --grep='Merge pull request'

Copy the commit hash, which looks something like this:


Revert on master

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

However, reverting on a branch with a PR (pull request) is safer and better practice.

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 and open a PR (pull request):

git push -u origin revertBranch

Please support this site and join our Discord!