First, check if you still have access to those files through the "local history" (as recorded by your IDE, not Git)
For instance, the Local History VSCode extension, as suggested here, can help.
If not, double-check your OS backup feature, like for MacOS Time Machine status, in case you could restore them from a backup.
Finally, since you have added those files to the index, check git fsck
git fsck --cache --no-reflogs --lost-found --unreachable HEAD
From the SHA1 listed, you can do a git show
:
git show "<SHA-1 REFERENCE TO THE BLOB OBJECT HERE>" > lost_file.txt
As noted by torek in the comments:
Note that you can also find the contents of each of those "unreachable blob"s in the .git/lost-found/other
directory.
This is often quicker and easier than git show
since you can cd .git/lost-found/other
, and then grep expected-string *
to find the file(s) that have the expected string.