Unfortunately : the content of your files has to somehow land in git if you want to retrieve your files.
git checkout -- .
is one of the few destructive commands (along with git reset --hard
and git clean -f
), which can remove content from your disk without storing it in git beforehand.
So git alone will not help you there ; you would have to turn to your IDE's history, or file recovery utilities.
For the record, here are actions that somehow "store content" in your repository :
git commit
, obviously ...
git stash
: this command actually creates complete commits, the last one you created will not expire, previous stashes will expire according to reflog expiry rules (default retention is 30 days, see help on git gc)
git add [file]
(even without running git commit
) : this writes the content of the file somewhere in git's database ; the file will not be stored along with its name but you can resort to some tricks to scan the files (blob
s in git parlance) by their content. The default retention period for "loose files" is 2 weeks (see help on git gc)