What is the difference between git reset and git restore?
Answer
Git 2.23 (2019) split the overloaded git checkout command into two more focused commands: git restore and git switch. git restore is specifically for restoring files in the working tree or staging area — discarding changes: git restore file.txt — discard working directory changes to file.txt (revert to staged version or last commit); git restore --staged file.txt — unstage a file (remove from staging area, keep working directory changes); git restore --source HEAD~2 file.txt — restore file to its state 2 commits ago; git restore . — discard all working directory changes. git reset is for moving the branch pointer and adjusting the commit history: git reset HEAD~1 — undo last commit (unstages changes); git reset --hard — discard commits and changes; git reset --soft — undo commits but keep staged. Summary: use git restore to discard file changes without touching commit history; use git reset to undo commits and rewrite commit history. Both git restore and git switch are now recommended over git checkout for clarity, though checkout still works.