Safely Undo a Commit With git revert
Create an inverse commit instead of rewriting shared history.
Run git revert <sha> to add a new commit that undoes the chosen one.
01Command
Command
$ git revert <commit-sha>02What it does
Unlike reset, revert appends rather than rewrites, so it is safe on branches others have pulled. It is the standard way to roll back a bad release or configuration change in a deployed repository.
03Risk
!Warning: Reverting a merge commit needs -m to choose the mainline; reverting several commits can conflict.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- git-revert documentationEvidence: Documents git revert, which records a new commit that reverses an earlier one.
Last verified: 2026-10-13 · Category: Developer