Git Checkout File
Question
What does git checkout -- file do?
Hint
checkout -- restores the last committed version.
Explanation
git checkout -- file (or git restore file) discards uncommitted changes in the working directory, restoring the file to its last committed state. This is destructive — your changes are lost. It only affects the working directory, not the staging area. To unstage a file, use git reset HEAD file. To restore both staged and unstaged, use git restore --staged --worktree file.
Related Resources
Related Lessons
- Git Reset
Learn git reset.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.