0

I used git reset --hard without any commits yet. I got this link on stackoverflow Undo git reset without any commits yet and I was able to get some files in the .git lost-found folder.

But the file are dangling blob which I cant work on. they are just plain.

How do I get these files back to original form thanks

techstack
  • 1,367
  • 4
  • 30
  • 61
  • If you can get the original file name, use `git show $blobsha1 > $filename`. – ElpieKay Feb 17 '20 at 08:48
  • I got files like this `dangling blob ebdf473df98ec286c8f327346a5e930deab5c72c dangling blob f29f55cfdd533f952931e684df1957b417afecb3 dangling blob f47fc509285134341b45ffbddf47a6dfc2f4a370 dangling blob f71f2d93294a67ad5d9300aae07973e259f26068 dangling blob f8dfa5a0df5fc454d87c54fb702ad3c245a6b524 dangling blob fa3fd00fe9cedb05370d8cd1681d53c1adee3113` – techstack Feb 17 '20 at 08:50
  • its the whole project that was lost. just the original project root folder is available – techstack Feb 17 '20 at 08:52
  • You didn't even make the very first commit? `git show ebdf473df98ec286c8f327346a5e930deab5c72c` prints the content, and you can redirect it to a file. – ElpieKay Feb 17 '20 at 08:54
  • Yes, I haven't committed. The command you suggested is not bringing back the file – techstack Feb 17 '20 at 09:22
  • Say the filename is `foo.java`. Use `git show ebdf473df98ec286c8f327346a5e930deab5c72c > foo.java` so that `foo.java` is created with the content stored in the blob `ebdf473df98ec286c8f327346a5e930deab5c72c `. – ElpieKay Feb 17 '20 at 09:51

1 Answers1

1

I've experienced the lost of files that weren't committed too, and the only solution to retrieve them is not to rely on git, but rather on anything else that can cancel the action of deleting the files.

In my case, cancelling the actions (by that I mean CMD+Z) on my IDE restored the files (I was using RubyMine).

Good luck!

Benjamin Cbr
  • 536
  • 4
  • 13