· #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:
# Discard changes in the working treegit restore file.ts
# Unstage (but keep the change)git restore --staged file.tsThe intent is now obvious from the command name. I keep checkout only for switching branches.