← back to diagnosis

discard unstaged changes

danger

Throw away local modifications. Be careful — discarded changes are gone for good.

$ git checkout -- <filename>
$ git checkout .

This throws away all unstaged modifications to tracked files. Gone for good.

discard untracked files

danger

Files that were never tracked by git. Because they were never committed, git cannot recover them.

$ git clean -n # preview what will be deleted
$ git clean -f # actually delete

Always run with -n first to preview. Files deleted by git clean are gone permanently — they were never in git's history.