git restore
Restore working tree files or staged changes to a previous state
Practical example
git restore src/index.ts # discard unstaged changes in one file git restore --staged src/index.ts # unstage a file (undo git add) git restore --source=HEAD~1 . # restore all files to how they were 2 commits ago
Command overview & how it works
A modern command (introduced in Git 2.23) for restoring files to a known state, replacing the confusing dual use of git checkout. Use git restore <file> to revert a file in your working directory back to the last committed state — discarding uncommitted changes. Use git restore --staged <file> to unstage a file (the inverse of git add) without changing the working directory. Use git restore --source=HEAD~1 <file> to restore a file to how it looked two commits ago. Use git restore . to restore all files in the current directory. Unlike git reset, restore operates at the file level and does not move branch pointers. Unlike git checkout, its behavior is predictable and focused — it always restores files, never switches branches.
Disaster-proof your Git workflow with the Field Guide
Learn how to rescue deleted branches, revive detached HEADs, and undo bad rebases without panic. 97-page PDF + ePub — ₹499.
Practical tips
- Discard uncommitted edits to a single file with git restore <file> — far safer than a blanket reset.
- Unstage a file with git restore --staged <file>, the inverse of git add.
- Restore from a specific point with git restore --source=HEAD~1 <file> to bring back an earlier version.
Deep-dive guides & tutorials
In-depth walkthroughs and practical scenarios related to git restore
- Tutorial
How to Undo Almost Anything in Git
From amending commits to recovering deleted branches — a practical guide to Git's safety net commands.
7 min readRead guide - Tutorial
Git Reflog: Recover Lost Commits and Branches
Deleted a branch? Lost commits after a reset? Git reflog tracks every movement of HEAD and can recover what seems lost forever.
5 min readRead guide - Tutorial
Git Stash: Save and Restore Work in Progress
Stop committing half-finished work. Learn how git stash temporarily shelves changes so you can switch contexts cleanly.
5 min readRead guide
Related commands
More from Undoing Changes