Revert
In one line
Reverting creates a new commit that undoes the changes of a specified commit, preserving the original history.
In simple words
git revert <commit> creates a new commit that is the exact inverse of the specified commit. If the original commit added a line, the revert removes it. If the original changed a value, the revert changes it back.
Revert is the safe way to undo a commit on shared branches because it adds to history rather than rewriting it. The original commit stays in the log — anyone who has already pulled is not affected.
This is different from git reset, which moves the branch pointer and effectively "deletes" commits from history (rewriting it). Use revert for shared branches (main, develop) and reset for local branches where rewriting history is acceptable.
Example
# Revert the last commit
git revert HEAD
# Revert a specific commit
git revert abc123
# Revert without opening editor
git revert --no-edit abc123Revert creates a new commit that undoes the specified commit's changes.
Common confusions
Confused with: reset
The difference: revert adds a new commit that undoes changes (safe, preserves history); reset moves the branch pointer backwards (rewrites history, dangerous for shared branches).
Related terms
Related Resources
Related Lessons
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.