git checkout -- file.txt

Category: Git - Core

git checkout -- file.txt

Discard unstaged changes in a file (restore from HEAD)

Discards all unsaved changes to a file, restoring it to how it looked in the last commit (HEAD).
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.