Revert a Commit on GitHub: Web UI + Git CLI (2026 Guide)
If a bad commit is already pushed, revert is usually the safest fix. On GitHub, you can often click Revert from the commit or PR page, then merge the generated rollback pull request.
When GitHub cannot auto-revert (usually conflicts), use CLI fallback with git revert. This guide gives both paths with copy/paste commands.
Table of contents
1. Quick decision: GitHub UI vs CLI
| Situation | Use this | Why |
|---|---|---|
| One bad commit, no expected conflicts | GitHub commit page Revert | Fastest route: GitHub creates revert branch and PR for you. |
| Merged PR needs rollback | GitHub PR page Revert | Automatically builds a rollback PR from the merge commit. |
| Revert button missing or conflicts expected | git revert in CLI |
Full control over conflict resolution and commit message. |
| Pushed merge commit rollback | git revert -m 1 <merge-hash> |
Required for merge commits because parent selection is explicit. |
CLI quick recipe (shared branch)
git switch main
git pull --ff-only
git revert <commit-hash>
git push origin main
CLI quick recipe (merged PR rollback)
git show --no-patch --pretty=raw <merge-hash>
git revert -m 1 <merge-hash>
git push origin main
2. Revert one commit in GitHub UI
Use this when a single commit introduced a bug and you want a PR-based rollback from the web interface.
- Open your repository on GitHub and navigate to the commit (for example from the commit history or a merged PR timeline).
- On the commit page, click Revert.
- GitHub creates a new branch and opens a pull request with the inverse changes.
- Review CI checks, request approvals if needed, then merge the revert PR.
After merge, GitHub has created a normal revert commit. No history rewrite is required.
3. Revert a merged pull request in GitHub
For rollback of a merged PR, GitHub usually shows a Revert button directly on that PR page.
- Open the merged PR.
- Click Revert.
- GitHub generates a new PR that reverts the merge commit.
- Run your normal release checks, then merge.
For a dedicated diagnostic flow for this exact problem, read GitHub Revert Button Missing Fix Guide.
4. CLI fallback when Revert button is missing
Revert a normal commit by hash
git switch main
git pull --ff-only
git log --oneline --decorate -n 20
git revert <commit-hash>
git push origin main
Revert a merge commit (common for merged PR rollbacks)
# inspect parent order first
git show --no-patch --pretty=raw <merge-hash>
# keep parent 1 (usually mainline)
git revert -m 1 <merge-hash>
git push origin main
Revert multiple commits as one rollback commit
git revert --no-commit OLDEST^..NEWEST
git status
git diff --staged
git commit -m "Revert problematic release commits"
git push origin main
If you accidentally reverted the wrong commit, use:
git revert <revert-commit-hash>
git push origin main
5. Verification and conflict handling
Before pushing
git status
git log --oneline --decorate -n 8
git show --name-only HEAD
If revert has conflicts
# resolve files manually, then:
git add <resolved-files>
git revert --continue
# if needed, cancel:
git revert --abort
After merge or push, validate the app behavior and monitor alerts before applying additional rollback commits.
6. FAQ
Does GitHub Revert delete commit history?
No. GitHub Revert creates a new commit that inverses earlier changes, just like git revert in CLI.
Can I revert an old commit, not just the latest?
Yes. You can revert any reachable commit by hash. Older commits can produce conflicts if later commits touched the same lines.
Should I use reset instead of revert on GitHub?
Not for shared branches. git reset requires force push and rewrites history. Use git revert for pushed commits.
Why did GitHub open a PR instead of reverting directly to main?
GitHub uses a branch + PR flow to keep review and CI checks intact. Merging that PR applies the rollback safely.
Where should I learn merge revert parent selection?
Use Git Revert a Merge Commit for detailed -m parent guidance.
Related Resources
-m parent choice before reverting merged PRs.
Git Undo Decision Guide
Choose reset vs revert vs restore in seconds.
Git Commands Cheat Sheet
Quick daily reference for revert, reset, restore, log, and more.