git restore

Discard edits in a file or unstage it

What it does

Without flags, git restore brings a file back to its staged version, or to the last commit if it was never staged. Put simply, it throws away edits that have not been through git add.

With --staged it works on the index instead: the file leaves the index and your edits stay in it. This undoes git add. The command arrived in git 2.23; before that the same was done with git checkout -- <file> and git reset <file>.

Careful. git restore <file> without --staged erases uncommitted edits in the file. They cannot be brought back: git never saved them.

Syntax

git restore <file>
git restore --staged <file>

Examples

Related commands

Practise · All commands