Reputation: 427
I need help, I had files that were not added to the repo yet. I did
git add this.php
git add file.php
then I decided I wanted to unstage them so I did
git reset --hard HEAD
Now these files are gone. How can I recover these files?
Upvotes: 0
Views: 79
Reputation: 265918
Luckily for you, you added those file to the index before nuking them from your working copy. In this case they are already contained in Git's object database. (First create a backup, just in case you mess something up).
Run git fsck
(maybe with --full
flag) and look out for "dangling blobs". Then use git show $hash
to display the contents of the blobs. If you find your files (there might be several similar versions), use git show $hash > path/to/file
to write them to disk again.
Upvotes: 5
Reputation: 9654
You cannot recover the files after a hard reset without having committed them.
You should have rather done a soft/mixed reset, which will just unstage the files. You can see the same suggestion from git when you do a git status
after staging the files.
Upvotes: 0