git restore
Restores working tree files. Introduced in Git 2.23 as a safer alternative to git checkout for file restoration.
Syntax
git restore [<options>] [--] <pathspec>...
Options
- --staged / -S: Restores the file in the staging area (unstages it)
- --worktree / -W: Restores the file in the working directory (default)
- --source=<tree>: Restores from a specific commit or branch instead of the index
- -p / --patch: Interactively choose hunks to restore
Example
git restore src/app.ts git restore --staged src/app.ts git restore --source HEAD~2 src/app.ts
Tip
Use --staged to unstage files and --source to restore from a specific commit.