git revert Undo a commit by adding a new one
Creates a new commit that reverses the changes from an earlier commit. History is kept intact, which makes it the safe way to undo something already shared.
Synopsis
git revert [OPTION]... COMMIT...
Common options
| Option or form | What it does |
|---|---|
-n, --no-commit | Apply the reversal to your files without committing |
-m N | Revert a merge commit, choosing parent N as the mainline (usually 1) |
--no-edit | Accept the default message |
--continue, --abort | Resume or cancel after a conflict |
A..B | Revert a range of commits |
Examples
git revert HEAD
[main 7c6d5e4] Revert "Add contact form"
2 files changed, 41 deletions(-)
git revert 3f2a9c1 --no-edit
git revert -m 1 9a8b7c6
git revert -n 3f2a9c1
Notes
- Revert only changes the files affected by that one commit. Later work stays.
- Reverting a merge means Git may skip those changes if you merge the same branch again. Revert the revert first.
- Use revert for pushed commits and reset for local-only ones.
See also
Last reviewed 2026-10-09.