Skip to content

Git revert and rollback quick reference

One-page cheat sheet for single commit rollbacks, range reversions, merge commit reverts, and re-reverting feature branches.


1. Quick command matrix

Scenario Command
Revert single commit git revert <commit-sha>
Revert without opening editor git revert --no-edit <commit-sha>
Revert commit range git revert --no-edit <start-sha>^..<end-sha>
Stage range into single rollback commit git revert --no-commit <start-sha>^..<end-sha>
Revert merge commit to keep mainline git revert -m 1 <merge-sha>
Revert merge commit to keep feature branch git revert -m 2 <merge-sha>
Restore feature branch after merge revert git revert <revert-commit-sha>
Abort an in-flight revert on conflict git revert --abort
Continue after resolving conflicts git revert --continue
Skip unresolvable commit during range revert git revert --skip

2. Step-by-step merge revert

When a bad pull request lands on main and breaks production:

# 1. Identify the merge commit SHA and verify parent 1 is mainline
git log -1 --pretty=format:"Commit: %h | Parents: %p%n" <merge-sha>

# 2. Revert the merge commit preserving mainline (parent 1)
git revert -m 1 --no-edit <merge-sha>

# 3. Verify working directory status
git status

# 4. Push rollback commit to remote
git push origin main

3. Atomic multi-commit rollback for pull requests

When rolling back multiple related commits in one clean pull request:

# 1. Create a rollback branch
git checkout -b rollback/incident-402 main

# 2. Revert range into staging area without committing
git revert --no-commit old-sha^..new-sha

# 3. Create single commit
git commit -m "fix(rollback): revert changes from v2.3.1"

# 4. Push branch and open PR
git push origin rollback/incident-402

4. Restoring code after a merge revert

When ready to re-introduce a feature branch that was previously reverted on main:

# 1. On main, find the revert commit
git log --grep="Revert" -n 5 --oneline

# 2. Revert the revert commit
git revert <revert-commit-sha>

# 3. Merge the feature branch containing new fixes
git merge feature-branch

# 4. Push main
git push origin main