Ad space (banner)
🌿Git Lessons
Lesson 38 / 59

Discarding File Changes with git checkout --

This lesson covers discarding a file's changes with git checkout --. It's for anyone searching "git checkout -- usage."

git checkout -- filename reverts a specific unstaged file back to the state of its last commit. Use it when you decide "actually, never mind this change."

In Try It, run git checkout -- app.js. The uncommitted changes to app.js are discarded, and it returns to its state as of the most recent commit.

A common early mistake is not realizing this operation can't be undone — it completely discards your uncommitted changes, so it's worth being genuinely sure the change is unwanted before running this. In real teams, this command gets used to revert just one specific file back to its original state, such as when an experimental change didn't pan out.

Git
Try it (type this into the pseudo terminal)
git checkout -- app.js

🧑‍💻 You can type this command into the Git pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)