Skip to content

Instantly share code, notes, and snippets.

@pablocattaneo
Last active April 30, 2025 14:31
Show Gist options
  • Save pablocattaneo/0aa2925015173dcc2c66f66407d56521 to your computer and use it in GitHub Desktop.
Save pablocattaneo/0aa2925015173dcc2c66f66407d56521 to your computer and use it in GitHub Desktop.
Yes, absolutely — you can **revert a problematic pull request (PR)** from `dev` without rewriting history. Here's how:
---
## ✅ Option 1: Revert the Entire PR Using `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:
```bash
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:
```bash
git revert -m 1 <merge-commit-hash>
```
- `-m 1` tells Git to treat parent #1 (usually the `dev` branch) as the mainline.
- This creates a new commit that undoes all changes from the merged PR.
Then push the result:
```bash
git push origin dev
```
---
## ✅ Option 2: Revert Individual Commits (if not merged with a merge commit)
If the PR was **squash merged** or **rebase merged**, then it won’t have a merge commit. You’ll need to:
1. Identify the commit(s) introduced by the PR.
2. Revert them manually:
```bash
git revert <bad-commit-hash>
# Or for multiple:
git revert <start-hash>^..<end-hash>
```
Then push:
```bash
git push origin dev
```
---
## 🔄 What Happens After Reverting?
- The **bad changes are undone**, but the history remains intact.
- The PR remains marked as "merged", but its code is no longer present in `dev`.
- You (or the original developer) can later fix the issues and create a new PR if needed.
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment