git revert
Creates a new commit that undoes the changes from a previous commit, preserving history.
Syntax
git revert [<options>] <commit>...
Options
- --no-commit / -n: Applies the revert to the working directory without creating a commit
- --no-edit: Uses the default revert message without opening an editor
- --abort: Cancels the revert operation
- --continue: Continues after resolving conflicts
- -m <parent-number>: Specifies the parent for reverting a merge commit
Example
git revert abc1234 git revert HEAD git revert --no-commit HEAD~3..HEAD
Tip
Unlike reset, revert is safe for shared branches because it does not rewrite history.