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
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.