Git 2 reference · Undoing Changes
git restore Command (Git)
Discard working-tree changes to files, or unstage files, without touching other work.
Git 2
Syntax
git restore [--staged] [--source COMMIT] PATH...
Parameters
| Parameter | Description |
|---|---|
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
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.
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.
Related
git reset· Move the current branch to another commit, keeping changes staged (--soft), unstaged (default) or discarding them (--hard).git switch· Switch to another branch, or create one and switch to it with -c; the modern replacement for git checkout branches.- Undoing Changes · tutorial