Git Tips Slides
PageUp x2: previous · PageDown x2: next · Home: index

restore, revert, reset

These three commands all start with re, so new Git users often mix them up.

The order above is intentional. It goes from safer and more local to more dangerous:

  • restore: restore files
  • revert: reverse a commit by adding a new commit
  • reset: re-set the branch pointer

Rough mental model:

  • restore changes files in your working tree or index.
  • revert keeps history intact and records a new commit that undoes an older one.
  • reset moves HEAD and usually the current branch.

Examples:

# Restore one file from main.
git restore -s main path/to/file

# Undo an old commit safely by creating a new commit.
# Both the old commit and the new undo commit stay in the history.
git revert <commit-hash>

# Move HEAD and the current branch back by one commit.
git reset --hard HEAD~1

If you are unsure, use restore for files and revert for published history.

Be careful with reset, especially after pushing. If unsure, use revert, not reset.