Recover Deleted Files with Eclipse

Previously, I wrote about how to recover deleted files with git, and while I was writing that post I remembered that I had done something similar with eclipse as well. Eclipse keeps a history of the changes, and all these changes are stored in a folder called .metadata/.plugins/org.eclipse.core.resources/.history in the workspace:

~/Code/java/workspace/.metadata/.plugins/org.eclipse.core.resources/.history % ls
0 16 1c 24 2f 36 3f 45 6f 75 7e 86 8f 96 a0 a7 ae b3 bb c1 c8
cf d6 df e6 ed f2 f9 13 1b 22 2e 35 3e 44 4b 51 57 61 69 7 76 8
87 9 97 a1 a8 af b5 bc c2 c9 d1 d8 e0 e7 ee f3 fa

~/Code/java/workspace/.metadata/.plugins/org.eclipse.core.resources/.history %
  find . -type f | wc -l
     126

~/Code/java/workspace/.metadata/.plugins/org.eclipse.core.resources/.history %

There are a lot of files in there. Eclipse keeps several versions of each file of the workspace, so we have to narrow down the search for the one to be recovered using a specific text from its content, because the file names aren’t that descriptive (it is a kind of hash created from the content of the file):

~/Code/java/workspace/.metadata/.plugins/org.eclipse.core.resources/.history % ls 16
203eb88425ac00111ca3dd466babd3de

~/Code/java/workspace/.metadata/.plugins/org.eclipse.core.resources/.history %

In this case, I knew that I was looking for a file named build.xml, which was the only file containing the text ‘crap4j’. Additionally, I needed the latest version, so my command looked like this:

~/Code/java/workspace/.metadata/.plugins/org.eclipse.core.resources/.history %
  ls -tl `grep -lr crap4j *` | head -5
-rw-r--r--  1 zsolt  staff   2.6K Jun  2 23:58 a/70ebedd3f7ac00111ca3dd466babd3de
-rw-r--r--  1 zsolt  staff   2.2K Jun  2 23:57 12/00ae5bacf5ac00111ca3dd466babd3de
-rw-r--r--  1 zsolt  staff   2.1K Jun  2 23:57 49/c0ff3a9df5ac00111ca3dd466babd3de
-rw-r--r--  1 zsolt  staff   2.1K Jun  2 23:57 84/600caa95f5ac00111ca3dd466babd3de
-rw-r--r--  1 zsolt  staff   2.1K Jun  2 23:56 4f/707c6c85f5ac00111ca3dd466babd3de

There it is. The a/70ebedd3f7ac00111ca3dd466babd3de version is the one I was looking for.


comments powered by Disqus