2

I was using atom text editor with a github integration when I somehow found myself with all my local personal desktop files (videos, images, notes, etc.) in the "unstaged" area. To get rid of it I clicked "discard changes" for all the files which removed them from my desktop and subsequent folders.

After realizing the fatal mistake I made the next day. I noticed a slightly transparent folder on my desktop labeled .git which is about 20gb worth now. I have looked into other posts but they haven't been much help. I've already closed atom and re-opened it, and pushed a request through last night, so simply clicking undo discard doesn't work. I was thinking about system restore, but maybe as a last resort.

What I see in the .git folder

1 Answers1

1

If those files were added, not committed, they should be recoverable.

See "Introducing git-recover" from Edward Thomson, and its git-recover script.
However, it might not know the file names to recover, and it seems to be a file-by-file process.

The OP Calvin Leung references "How To: Recover From a Git Hard Reset" from [Carrie Guss]6.
She gets all the missing blobs:

    for blob in $(git fsck --lost-found | awk '$2 == "blob" { print $3 }'); do \ 
      git cat-file -p $blob > $blob.txt; done

Then she uses that content to deduce the file names.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @CalvinLeung You need to install that script in your %PATH%. – VonC Oct 07 '18 at 05:25
  • sorry, I deleted my comment after I saw the instructions at the very bottom on another page. Thank you though! – Calvin Leung Oct 07 '18 at 06:01
  • I was able to recover some changes done on the most recent file but I am unable to find the majority of the files. I have tried switching directories and running it but it unable to locate any files to recover. – Calvin Leung Oct 07 '18 at 07:01
  • @CalvinLeung Then plan B: something like https://www.howtogeek.com/169344/how-to-recover-a-deleted-file-the-ultimate-guide/ – VonC Oct 07 '18 at 07:06
  • Thank you, but I'll keep trying plan A for now. I'll keep you updated. – Calvin Leung Oct 07 '18 at 07:12
  • So I did more digging around by running git fsck and I found a bunch of dangling blobs. I think this might have something to do with my files. – Calvin Leung Oct 07 '18 at 08:40
  • @CalvinLeung Yes, that is what the git recover script is supposed to be doing as well: https://github.com/ethomson/git-recover/blob/f7ee394a3ecce2b5b8b0ac94da109058e48678ba/git-recover#L93-L101 – VonC Oct 07 '18 at 08:52
  • Yeah it was still unable to find any "recoverable orphaned blobs." Update: I was able to recover the files with git fsck lost-found --, and am able to view content using git show "blob name here." I currently have a .git folder with with a bunch of random file names and no file type. My new dilemma is going through each one and trying to figure out file name and type. Is there an easier way for this? – Calvin Leung Oct 07 '18 at 10:35
  • @CalvinLeung Not sure: you have https://stackoverflow.com/a/12439261/6309 and https://stackoverflow.com/a/37399626/6309. – VonC Oct 07 '18 at 10:56
  • Just for anyone who checks this later the correct command I used was "git fsck --lost-found" not "git fsck lost-found --" as I initially stated minus the quotes of course. – Calvin Leung Oct 07 '18 at 11:07
  • Thanks @vonC I'll take a look at those right now. Thank you for being patient with me. – Calvin Leung Oct 07 '18 at 11:08
  • thank you for your help. You're links somewhat helped but I found another post that was more straight forward. https://medium.com/@CarrieGuss/how-to-recover-from-a-git-hard-reset-b830b5e3f60c – Calvin Leung Oct 08 '18 at 04:20
  • @CalvinLeung Great! I have included your reference in the answer for more visibility. – VonC Oct 08 '18 at 04:25
  • awesome thanks! also there was a small error in the code. This is the correct one below. Notice the quotes. for blob in $(git fsck --lost-found | awk '$2 == "blob" { print $3 }'); do \ git cat-file -p $blob > $blob.txt; done – Calvin Leung Oct 08 '18 at 04:41