1

I have completely messed up my computer. I had used Git couple of years back and now today I had to work on a project when I started using git.

  1. I opened terminal went to cd Desktop
  2. Then git add (forgot to mention the name of directory I wanted to add)
  3. Checked status of git and it showed all the directories/subdirectories on my desktop as untracked files.
  4. I got panicked and after reading slightly on internet executed git command to clean with -fd.

While I was working on my desktop I noticed my desktop folders are vanishing I closed the terminal and thought its not possible and then did git clean -fd again .. but yeah it was happening and within minutes my desktop was empty. I again closed terminal but there was only one or two folders left and rest all was gone which included all my work, documents, 1000s of images, Music, Videos etc. Now I don't know how to retrieve it. Can it be retrieved via git or even via hardware recovery software?

halfer
  • 19,824
  • 17
  • 99
  • 186
White. S
  • 41
  • 1
  • 6
  • see http://stackoverflow.com/questions/6267180/can-i-undo-a-git-clean-fdx – Haim Raman Apr 09 '17 at 11:16
  • 1
    Look at the post above you need a recovery tool specific to your os. from git point of view it's gone – Haim Raman Apr 09 '17 at 11:39
  • I don't mind even if it is a recovery tool, I just need my data back.. The only thing I want to be sure of is that that tool retreieves the files I lost via git clea – White. S Apr 09 '17 at 11:44
  • 5
    `git clean -fd` deletes files that are untracked by `git`. Recovering them will have nothing to do with `git`. I've hope you've been keeping good backups, because you're going to need them. If you *haven't* been backing things up, use this as a wakeup call and make sure you're prepared next time it happens. – larsks Apr 09 '17 at 12:39
  • 1
    You'll likely need data recovery software suitable for your operating system (e.g. Windows). The main thing is **don't use your computer until you've run your data recovery** - saving documents and installing things is likely to overwrite your data on disk. I haven't used data recovery tools, but [here is some Windows ones](https://duckduckgo.com/?q=windows+data+recovery). – halfer Apr 09 '17 at 20:59
  • [If you're using Eclipse and you've "only" lost text/code, this may help.](https://stackoverflow.com/a/52298924/1529709) – zb226 Sep 13 '18 at 10:47

1 Answers1

3

Unfortunately you're on thin ice.

The "problem" with "untracked" files and git is that git explicitly doesn't know about them. Sure, it sees them on the file system, that's why it lists them, but you have not yet told git to track these files.

As such, git has no copy of them anywhere.

Additionally, when git deletes files it issues a normal delete to the file system, not a delete to the trashcan or similar, which means that there is no easy way to bring back your files.

So here's what you need to do.

Stop using your computer right now. Go to a different computer and download an undelete tool, preferably a portable one that doesn't need installing.

The reason for this is that deleted files are not tracked by the file system any more. It does not prevent new files from overwriting the space where the old files used to be. The longer it takes from the point where you deleted the files until you restore them, the fewer files you will get back in one piece.

Put this undelete tool on a USB drive and then plug that into the computer on which you deleted the files.

Run the undelete tool and ask it to help you find files you have deleted.

Cross your fingers.

When you're done, and get back as much as you can, install some backup software. If you care enough about your files to complain when they're gone, make sure they don't get lost in the first place.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825