What is the difference between git restore and git reset?
git restore and git reset are both used to undo changes, but they work at different levels and with different consequences.
git restore - rolling back files
git restore is intended only for working with files.
What it does:
- undoes changes in the working tree
- removes files from the staging area (unstage)
- does not work with the commit history
- does not change history
Examples:
bash
git restore file.txt # roll back a file in the working directory
git restore --staged file.txt # remove a file from the staging areaUsed when you need to:
- undo local changes in a file
- remove a file from the index before a commit
git reset - rolling back state and history
git reset works with the branch pointer and commits.
What it does:
- moves the branch pointer (HEAD)
- can change the staging area
- can change the working directory
- can rewrite history
Modes:
bash
git reset --soft # changes only the history
git reset --mixed # history + staging area (default)
git reset --hard # history + staging area + working directoryUsed when you need to:
- undo a commit
- roll a branch back
- completely remove changes
The key difference
| Criterion | git restore | git reset |
|---|---|---|
| Works with files | Yes | Partly |
| Works with commits | No | Yes |
| Changes history | No | Yes |
| Safe for public branches | Yes | No |
| Main purpose | undoing changes | rolling back state |
Short phrasing for an interview
git restoreis used to undo changes in files and the staging area without changing history.git resetis used to roll back commits and the branch state, and it can rewrite history.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.