Git Revert Cheat Sheet

Git revert — safely undo commits by creating new inverse commits. Revert vs reset, reverting merge commits, and best practices for shared branches.

Last Updated: May 1, 2025

Revert Commands

git revert HEAD
Revert the most recent commit
git revert commit
Revert a specific commit by its SHA
git revert HEAD~3..HEAD
Revert a range of commits (oldest first)
git revert --no-commit commit
Revert without auto-committing (review changes first)
git revert --no-edit
Skip editing the auto-generated commit message
git revert --signoff
Add Signed-off-by line to the revert commit
git revert --continue
Continue revert after resolving conflicts
git revert --abort
Abort a revert that has conflicts

Reverting Merge Commits

git revert -m 1 merge-commit
Revert a merge commit (specify mainline parent)
git show merge-commit
Find parent numbers: Parent 1 = current branch, Parent 2 = merged
git revert -m 1 --no-commit merge
Review merge revert before committing
git revert merge-commit
Plain revert of a merge WILL FAIL — must use -m flag
git log --merges
List all merge commits to find the one to revert

Revert vs Reset

Aspectgit revertgit reset
SafetySafe — adds new commitDangerous — removes history
Shared BranchesRecommendedAvoid at all costs
Private BranchesWorks but verboseFaster, cleaner
Undogit revert the revert commitgit reflog recovery
HistoryFull audit trailHistory disappears
ConflictsMay have conflictsNo conflicts (just moves pointer)
Team ImpactNone — everyone pulls safelyForce push required — breaks others

Real-World Revert Patterns

ItemDescription
Revert the RevertIf you revert by mistake, revert the revert commit to restore
Partial Revertgit revert --no-commit → manually edit → commit only what you want
Sequential RevertsRevert multiple commits in reverse chronological order
Hotfix Rollbackgit revert the bad deploy commit on main — no force push needed
CI/CD SafetyRevert commits that broke CI, fix forward, then re-apply
Feature Flag + RevertShip behind flag, revert config change instead of code
Merge Revert GotchaRe-reverting a merge requires the SAME -m parent number
Pro Tip: Always use `git revert` on shared branches instead of `git reset` — reset rewrites history and will break your teammates' repos.