Git 2 reference · Undoing Changes

git restore Command (Git)

Discard working-tree changes to files, or unstage files, without touching other work.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git restore [--staged] [--source COMMIT] PATH...

Parameters

ParameterDescription
PATH Discard unstaged changes to PATH.
--staged Unstage (keep the changes in the working tree).
--source COMMIT Restore the file as it was in COMMIT.

Examples

Discard changes to a file
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'oops' > README.md
git restore README.md
cat README.md

Output

# Shop

Run this on your computer — see “Get Started” for setup.

Unstage but keep the change
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'v2' >> README.md; git add README.md
git restore --staged README.md
git status -s

Output

 M README.md

Run this on your computer — see “Get Started” for setup.

Was this page helpful?