restore is the precise undo for files
For years, "undo this file" in Git meant git checkout -- file, which was overloaded with branch switching and routinely confused beginners. Git 2.23 introduced git restore — a command whose only job is moving file content back across the three areas. Once you start using it, the old checkout-for-files invocations feel like accidents waiting to happen.
Three undo flavors cover almost everything. Discard unstaged edits: git restore file.js overwrites the working-tree version with the index version, throwing away the local edits. Unstage: git restore --staged file.js overwrites the index entry with the HEAD version, removing it from the next commit but keeping working-tree edits. Both at once: git restore --staged --worktree file.js rewinds both layers to the HEAD version, fully erasing recent work on the file.
The optional --source flag lets you restore from a different commit — restore --source=HEAD~3 -- file.js brings the version of file.js from three commits ago into the working tree (and optionally index). This is how you "go back to how it was last week" for one file without touching the rest of the project.
Treat restore as the quiet undo. It does not move branch pointers; it does not rewrite history; it does not affect other files. The blast radius is exactly the paths you list. That makes it safe to use freely — far safer than git reset --hard, which is often the wrong choice for a single-file mistake.