I once pushed a commit that broke production. The fix was already in progress but would take an hour. git revert let me undo the damage immediately while keeping full history of what happened.

Basic usage Link to heading

Revert the last commit:

git revert HEAD

Revert a specific commit:

git revert abc123

This opens an editor for the commit message. Save and close to complete.

Revert without opening editor:

git revert abc123 --no-edit

Revert multiple commits:

git revert abc123 def456

If there are conflicts, resolve them and continue:

git revert --continue

Or abort:

git revert --abort

When to use revert vs reset vs rebase Link to heading

  • git revert - Use on shared branches (main, develop). Creates a new commit that undoes changes. History is preserved. Safe.
  • git reset - Use on local branches only. Rewrites history by moving HEAD backward. Dangerous on shared branches.
  • git rebase -i - Use to clean up local commits before pushing. Can drop, squash, or edit commits. Never on shared branches.

The rule: if anyone else might have pulled the commits, use revert. If it’s only on your local branch, reset or rebase are fine.

For selective commit application, see git cherry-pick.

Further reading Link to heading