See Recover files in git after reset --hard on added files(not committed!). There's a bit of a short-cut you can use: instead of just:
git fsck
which prints a bunch of dangling blob
messages that you must save and check as shown in its accepted answer, use:
git fsck --lost-found
This time, instead of just saying dangling blob *hash
, Git will extract the contents of that "dangling blob" file into .git/lost-found/other
. The name of the extracted file will be the blob hash ID. The content will be either one of the files you git add
-ed with git add .
, or some other content left over from some other earlier operation that added content but ended up not using it. (In this case, since the Git repository itself is new, there should not be any such files.)
Unfortunately, the names of the files are all lost: they were in the index, but the index has now been re-set via git reset
and no longer has the files' correct names. If you can map from content back to file name manually, you can move or copy the files from the .git/lost-found/other
directory to exist under whatever names you had originally.
(When you are all done, you can remove the contents, if any, of .git/lost-found/commits
and anything remaining in .git/lost-found/other
. In your case there should be nothing in .git/lost-found/commits
.)