Yes, absolutely — you can revert a problematic pull request (PR) from dev
without rewriting history. Here's how:
git revert -m
If the PR was merged using a merge commit (the default for GitHub/GitLab), you can revert the whole PR cleanly with:
git checkout dev
git pull
git log --oneline
Find the merge commit from the PR (it will look like: Merge pull request #123 ...
), then run:
git revert -m 1 <merge-commit-hash>
-m 1
tells Git to treat parent #1 (usually the dev
branch) as the mainline.Then push the result:
git push origin dev
If the PR was squash merged or rebase merged, then it won’t have a merge commit. You’ll need to:
git revert <bad-commit-hash>
# Or for multiple:
git revert <start-hash>^..<end-hash>
Then push:
git push origin dev
dev
.