Tsallaka zuwa abun ciki
Justice Tech School

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.txt

Result

 M a.txt
one

Exercise

Unstage a file.

git restore  a.txt

Quiz Test

Can git restore a.txt be undone?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.