Git Restore
In one line
git restore discards uncommitted changes in the working tree or restores files from a specific commit, replacing git checkout for this purpose.
In simple words
git restore is the modern (Git 2.23+) command for undoing changes in the working tree. It replaces the overloaded git checkout for this specific job, making the intent clearer. You use it to discard uncommitted edits, restore deleted files, or copy a file's content from another commit into your working tree.
The two common forms: git restore <file> discards uncommitted changes to a file (restores it to match the index/staging area). git restore --staged <file> unstages a file (removes it from the index but keeps the working-tree changes), replacing git reset HEAD <file>. git restore --source=HEAD~1 <file> restores a file from an older commit.
restore only touches the working tree (or the index with --staged) — it never moves the current branch or HEAD. This makes it safer and more predictable than the old checkout overload. Pair it with git switch (for changing branches) for the modern, split-by-intent workflow.
Example
# Discard uncommitted changes to a file
echo "oops" >> app.js
git restore app.js # app.js back to staged version
# Restore a file you deleted (but haven't committed the deletion)
rm config.json
git restore config.json # file is back
# Unstage a file (keep the changes in working tree)
git add app.js
git restore --staged app.js
# Restore a file from 2 commits ago
git restore --source=HEAD~2 app.jsrestore discards working-tree changes. --staged unstages. --source=COMMIT restores from that commit. It never moves HEAD or the branch.
Related terms
Related Resources
Related Lessons
- Git Restore
Learn git restore.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.