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:
ad8a33e72fc9ed5769f96b0bbb1e222e4bebf44c
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