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 formWhat it does
-n, --no-commitApply the reversal to your files without committing
-m NRevert a merge commit, choosing parent N as the mainline (usually 1)
--no-editAccept the default message
--continue, --abortResume or cancel after a conflict
A..BRevert a range of commits

Examples

Undo the latest commit
git revert HEAD
[main 7c6d5e4] Revert "Add contact form"
 2 files changed, 41 deletions(-)
Undo a commit from earlier
git revert 3f2a9c1 --no-edit
Undo a merge, keeping the main line
git revert -m 1 9a8b7c6
Prepare a revert without committing it
git revert -n 3f2a9c1

Notes

See also

Last reviewed 2026-10-09.