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 filesrevert: reverse a commit by adding a new commitreset: re-set the branch pointer
Rough mental model:
restorechanges files in your working tree or index.revertkeeps history intact and records a new commit that undoes an older one.resetmovesHEADand 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.