Run git fsck
and look for dangling blob hash IDs (you can run git fsck --unreachable
if you prefer but for this case it should produce the same useful information, and --unreachable
disables --lost-found
). Add --lost-found
to make things much easier: for each of those "dangling blob" objects that git fsck
reports, Git will write a file to .git/lost-found/other/
with a bizarre hash-ID name such as 04d0fd1fe60702c2040f3658301ce7e322761ceb
.
Now that you have these files in .git/lost-found/other
, examine each file. One of them will contain the data you removed. The file name is gone, but the contents can be recovered this way.
If the file contents exactly match some committed file, it won't turn up in the lost-and-found, but in this particular case, that seems improbable.
(When you're done, you can simply remove the .git/lost-found
directory entirely. Be careful removing it of course!)
The hard way
If you use --unreachable
, you'll need to git cat-file -p
each hash ID, e.g.:
$ git fsck --unreachable
Checking object directories: 100% (256/256), done.
unreachable commit 06f1c305bbd945cb2b9533a4bb237b149cac26ce
unreachable blob 070d406b64141edb1f619acfc2e9d2f2d8a9fe6c
unreachable blob 20943aebb3b8f4b43e56009d4143744cf9d98239
unreachable blob 28b87432a538a032e3b6ac7cc3833023e6f505e5
unreachable tree 5645793dccf3ec49312efa72156b09effdec5e2a
...
Using git cat-file -p
on each of those blob
hash IDs, I see various bits of junk I git add
-ed or that Git created during merge conflicts or whatever. In your case, you'd get the initial file contents from your git add
s (plus, perhaps, some other junk: Git feels free to create trash objects, secure in the knowledge that after 14 or 30 or 90 days or so they'll be cleaned-up).