Git Cheatsheet - Quick Git Command Reference

Quick reference for common Git commands. Search, copy, and use Git commands instantly.

Share
Back to Git Cheatsheet

git restore

Restore working tree files (Git 2.23+)

Syntax

git restore [options] [--source=<tree>] <pathspec>

Common Options

OptionDescription
--stagedRestore from staging (unstage)
--source=<tree>Restore from specific source
-p, --patchInteractive restore selection
-W, --worktreeRestore working tree (default)
-s, --sourceSpecify restore source

Examples

git restore file.txt

Discard working tree changes

git restore --staged file.txt

Unstage file

git restore --source=HEAD~2 file.txt

Restore file to 2 commits ago

git restore .

Discard all working tree changes

Related Tools

More Code & Dev Tools