recovery

git restore

Modern command (Git 2.23+) for restoring working tree files from the index or a commit, or unstaging files. Replaces the confusing file-mode of 'git checkout'.

git restore [<options>] <pathspec>...

Common flags

Flag Purpose
--staged Unstage a file (restore index from HEAD)
--source=<commit> Restore file contents from a specific commit
--worktree Restore in the working tree (default)
-p / --patch Interactively pick hunks to restore

Examples

git restore src/app.js

Discard unstaged changes in a file

git restore --staged src/app.js

Unstage a file without touching the working copy

git restore --source=HEAD~2 README.md

Restore README to its version two commits ago

Gotcha

Without --staged, 'restore' overwrites working-tree changes irreversibly — there's no trash bin, so double-check paths.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge