git revert
Create a new commit that safely undoes a previous commit
Practical example
git revert HEAD # undo the latest commit safely git revert abc1234 # undo a specific commit git revert HEAD~3..HEAD # revert a range of commits
Command overview & how it works
Creates a brand new commit that inverses all the changes from a target commit, effectively undoing it without rewriting history. This is the safe undo command for commits that have already been pushed to shared branches. Unlike git reset, revert does not move branch pointers — it adds a new commit on top, so the existing history is preserved. Use git revert HEAD to undo the most recent commit, git revert HEAD~3 to revert the commit three steps back, or git revert <commit-hash> to target a specific commit. If the revert causes conflicts, resolve them normally and git revert --continue. Use git revert --no-commit to stage the inverse changes without automatically committing — useful for reverting multiple commits in a single commit. Revert is the default strategy for undoing changes in collaborative workflows.
Disaster-proof your Git workflow with the Field Guide
Learn how to rescue deleted branches, revive detached HEADs, and undo bad rebases without panic. 97-page PDF + ePub — ₹499.
Practical tips
- Prefer revert over reset for any commit that has been pushed to a shared branch — it adds a safe inverse commit.
- Revert a range with git revert HEAD~3..HEAD, or stack multiple --no-commit reverts into a single commit.
- If a revert conflicts, resolve the conflict, stage the files, and run git revert --continue.
Deep-dive guides & tutorials
In-depth walkthroughs and practical scenarios related to git revert
- Tutorial
How to Undo Almost Anything in Git
From amending commits to recovering deleted branches — a practical guide to Git's safety net commands.
7 min readRead guide - Tutorial
Git Reflog: Recover Lost Commits and Branches
Deleted a branch? Lost commits after a reset? Git reflog tracks every movement of HEAD and can recover what seems lost forever.
5 min readRead guide - Tutorial
Git Stash: Save and Restore Work in Progress
Stop committing half-finished work. Learn how git stash temporarily shelves changes so you can switch contexts cleanly.
5 min readRead guide
Related commands
More from Undoing Changes