0

I was trying to initialize git on one of my projects. I added all my files / folders to the staging area using git add *. I then committed a readme file, and then pushed it to remote repo. Then I committed 1 folder using git commit folder/* and then did another push.

But after that, I did a git reset --hard. Now all my files from the last few weeks are gone (I did not keep a backup of the project either), and I only have the readme file. Is there any way to recover the deleted files?

I tried getting the blob files using git fsck –lost-found, and restored them using git show -p --format=raw $blob > $blob.txt. But this gives me around 3000 blob files. How can I go through all these files to get the latest ones? Moreover, the filenames are random. Do I need to go through all 3000 files, match the appropriate files, and find out the latest version manually?

halfer
  • 19,824
  • 17
  • 99
  • 186
drunkenfist
  • 2,958
  • 12
  • 39
  • 73
  • possible duplicate of [Recover from git reset --hard?](http://stackoverflow.com/questions/5788037/recover-from-git-reset-hard) – kan Jan 20 '15 at 09:52
  • For future readers: the best advice is to add and commit your work several times a day, and push to a remote server at least daily. This note comes too late for the OP, but for users switching to a distributed version control system, the above is essential. – halfer Dec 20 '15 at 23:02

1 Answers1

0

Try reverting back to the commit in which "Then I committed 1 folder using "git commit folder/" and then did another push"

For that first do a git log Then identify the commit hash you want to revert to (say afb465c) Next git revert afb465c Hopefully, this will take your repo to the state just before the reset.

abhishek_M
  • 1,110
  • 11
  • 19