git restore

The command that throws away uncommitted changes to a file, or with --staged takes a file back out of the staging area.

Without --staged it discards uncommitted edits that Git has no copy of.

In more detail

git restore notes.txt copies the staged version back over the working tree file, discarding your edit with no way to recover it. git restore --staged notes.txt resets the staging area copy to the last commit and leaves your edit on disk. It was added in Git 2.23 to take over those jobs from git checkout.

Example

git restore --staged recipes.md

Related terms

Taught in

References