14927

Restore files deleted with git clean -df

Question:

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

Answer1:

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.

Answer2:

Short answer and most probable there is not!!

Still some IDE's track and store locally this information see for example: <a href="https://stackoverflow.com/questions/9750049/is-it-possible-to-restore-deleted-untracked-files-in-git" rel="nofollow">Is it still possible to restore deleted untracked files in git?</a>

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

Answer3:

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 <strong>a lot</strong> 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.

Recommend

  • Numpy - Finding matches across multiple co-ordinates
  • Mapping a function over two input lists
  • import XML to HTML
  • How to find multiple Pattern(s) (using Matcher) in Java
  • Creating a Countdown Watch with a slider in Xcode
  • How do I “decouple” my new android studio repro from my old eclipse repro?
  • getting cpu usage of one process using c++ (win32)
  • License error with Saiku Analytics Plugin on Pentaho 6 CE
  • Determine windows system wide font
  • Writing PHP in
  • Formula for Unique Hash from Integer Pair
  • AppleScript access Network Folder
  • sporadic ASP.NET data error: “Cannot find table 0”
  • Is it bad to use a malloc loop to guarantee a result from malloc?
  • Using python to determine if a timestamp is under daylight savings time
  • ASP Net Core - Mixing External Identity Provider with Individual User Accounts for Audit Tracking
  • Where and How To Define An Application Property? - JHIpster
  • How to attach php documentation in eclipse
  • Uploading image using SpringMVC 4.0 Multipart
  • Teradata Database 3130 Response limit exceeded?
  • Batch file to delete all folders in a directory except the newest folder
  • Change color of row programmatically in WatchKit
  • CDI: Injecting single instance works, but injecting Instance does not. Why?
  • How to retrieve a specific string from a specific list from a file with JSON in Python
  • Stitching 2 images (OpenCV)
  • Possible to get mouse events fired when cursor is outside page?
  • DIV instruction jumping to random location?
  • Debugging VB6 Code From Visual Studio 2010
  • How do I signal completion of my dataflow?
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • Diff between two dataframes in pandas
  • Moving Android View and preventing onDraw to be called over and over again
  • xtable package: Skipping some rows in the output
  • Parsing a CSV string while ignoring commas inside the individual columns
  • Avoid links criss cross / overlap in d3.js using force layout
  • Jquery - Jquery Wysiwyg return html as a string
  • Arrays break string types in Julia
  • WPF Applying a trigger on binding failure
  • Java static initializers and reflection
  • How can I remove ASP.NET Designer.cs files?