Skip to content
← All notes
· #git #cli

Undo working-tree changes with git restore

I always confused what git checkout -- file actually did — am I switching branches or discarding a file? Since Git 2.23 there’s a dedicated, explicit command for it:

Terminal window
# Discard changes in the working tree
git restore file.ts
# Unstage (but keep the change)
git restore --staged file.ts

The intent is now obvious from the command name. I keep checkout only for switching branches.

Source: https://git-scm.com/docs/git-restore