2

I was trying to clear my git after adding files from the wrong directory and ran the git clean -df function. This resulted in all my user data being deleted.

I haven't done anything more in git after this, and I don't dare to turn of my PC at the moment. However, I noticed that there is a .git folder which contains about 600MB of data. Is it possible that y files are stored there and can be recovered?

I run Windows 10 and do not have any backup or restore points for the user data folder.

Any help would be greatly appreciated as I had som really important data stored. Thank you

KebabJens
  • 21
  • 1
  • 1
  • 3
  • If those files weren't committed, there's nothing Git can do to restore them. This becomes a generic "how do I undelete files on Windows" question and should probably be moved to https://superuser.com. – Schwern Nov 15 '16 at 23:52
  • I never got to commit anything, so I gues I have to retrace my 2 last months of data input .. – KebabJens Nov 15 '16 at 23:59
  • There's any number of tools to undelete files. https://www.google.com/amp/www.howtogeek.com/169344/how-to-recover-a-deleted-file-the-ultimate-guide/amp/ – Schwern Nov 16 '16 at 00:12
  • Possible duplicate of [Is it possible to restore deleted untracked files in git?](http://stackoverflow.com/questions/9750049/is-it-possible-to-restore-deleted-untracked-files-in-git) – 1615903 Nov 16 '16 at 05:10

3 Answers3

3

There's no way to recover from this unless you had a backup or want to explore using undelete utilities. Git is not saving backups anywhere.

Jim Stewart
  • 16,964
  • 5
  • 69
  • 89
1

Short answer and most probable there is not!!

Still some IDE's track and store locally this information see for example: Is it still possible to restore deleted untracked files in git?

So depending on your IDE or text editor it still might be possible.

Community
  • 1
  • 1
PeCosta
  • 537
  • 4
  • 13
  • By IDE, do you mean my storage device? – KebabJens Nov 16 '16 at 00:08
  • @KebabJens No, Integrated development environment (IDE). For example Eclipse, Visual Studio, etc... – PeCosta Nov 16 '16 at 00:11
  • Aha, well I use Clion, but the folder tat was "cleaned" was my windows user folder, containing anything on my desktop, all my documents (word, excel, PDF etc.) and other things stored on my windows user account. so my programming files are still safe, but that is the least of my worries right now. – KebabJens Nov 16 '16 at 00:14
  • Well sorry then I did not understand that the deleted files extended beyond your programming files (code files you had not commited yet ) – PeCosta Nov 16 '16 at 00:19
0

If you're using Eclipse, and you're only missing code or text, don't despair, not all may be lost. Go to:

[WORKSPACE]/.metadata/.plugins/org.eclipse.core.resources/.history

Then use grep (*nix), FINDSTR (Windows) or a similiar tool to search for text snippets you know to have occurred in the deleted files. Eclipse keeps a lot of local history revisions around, so if you worked on these files recently, you will probably have a lot of matches. Then you need to find most recent one of these, which can be a bit tricky.

To give an example: After doing a quick git clean -d -fx to show this dangerous feature to a colleague, I was missing an untracked java code file, of which I knew it contained the String XrefCollector. I was able to find the last local history revision by doing this:

find . -printf "%T@ %p\n" | sort -n | cut -d" " -f2 | xargs grep -l XrefCollector | tail -n1

Here, find prepends the date (epoch) to the files, sort sorts (numerically), cut removes the date again, and xargs passes the filenames on to grep, which searches for the desired string. Finally, tail only shows the last line of output.

zb226
  • 9,586
  • 6
  • 49
  • 79