If you ran git add
on that file after you changed it, the content has been registered in .git
- it's present there and it can be retrieved. Though not easily - you'd have to find all the recent objects that were created by Git first:
find .git/objects/ -type f -printf "%T+\t%p\n" | sort
These are sorted by modification date, so the last ones were created recently. Make your way up - go through each of those objects and run this command until you find your content:
git cat-file -p [40 letter hash including 2-letter directory name]
Some of those objects are not files but trees (directories) and commits, skip them.
If you didn't run git add
then Git doesn't know about that file at all, so you can't ask Git to retrieve the file back.