Search notes:

git restore

Main options

The three main options of git restore are

Undoing an added file

Using --staged unstages a file that was added to the staging area:
get restore --staged added-file.txt

Getting back a deleted file

rm foo.c
git restore foo.c

Getting an «old» file

git restore --source HEAD~42 foo.c

Restore a file to a different directory

A file of a given commit can be restored to another directory like so
mkdir old-version
git --work-tree ./old-version restore -s 9442d6c77c path/to/file.txt
cd old-version/path/to
ls file.txt
Compare with git show

See also

Two new git commands meant to reduce git checkout confusion
git reset, git revert
git commands

Index