Safely Undo a Commit With git revert

Create an inverse commit instead of rewriting shared history.

macOSdiffgitcliLow risk
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

RiskLow risk
RequirementsGit 2.20+ (install with Homebrew or Xcode Command Line Tools)
CompatibilitymacOS with Git installed (Homebrew or Xcode Command Line Tools)
!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 documentation
    Git · vendor-doc · 2026-09-20
    Evidence: Documents git revert, which records a new commit that reverses an earlier one.

Last verified: 2026-10-13 · Category: Developer