Restore and Unstage
git restore file discards working changes. git restore --staged file unstages but keeps edits. Discarding cannot be undone.
Example
echo one > a.txt && git add a.txt && git commit -qm 'first'
echo two >> a.txt && git add a.txt
git restore --staged a.txt
git status --short
git restore a.txt
git status --short
cat a.txtResult
M a.txt one
Exercise
Unstage a file.
git restore a.txt
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.