How to recover a file deleted by SVN if you use Eclipse

If you arrived until here, maybe you have lost a file and you want to recover it, so summon up your patience (and get lucky).

Some days ago I was so happy working with Eclipse writing PHP code when I thought: «This is the moment to commit my work». And I did it.

Usually, making a commit makes your SVN to manage the files, synchronicing the modified ones, and storing the new changes in a secure place. But when more than one person is working on the same file, you have a lot of chances your SVN to become crazy getting in troubles. I lost almost the whole work of this day 🙁

Searching on internet (I can’t remember where) Thanks to Dani Bru and his invaluable help, he found the name of a magic directory where were supposed to rest an automatic set of backups. «Yes… of course!» I thought. I had no hope, but this was the only track to solve the problem, and we get to work.

Apparently, in some obscure and hidden place of your file system, Eclipse makes (at least one) a backup before a commit. And this is how we find the place:

First step

Open your terminal and write:

pedro@pedro-laptop:~$ updatedb

Be patient, this can take a while. Specially if you never did it before. The command updates the file system index, so we can get an accurate search in the next step. When it finalizes, you won’t get any output, just will return to the console.

Second step

Search the string org.eclipse.core.resources, which is the magic directory that can save our lifes (well, our day):

pedro@pedro-laptop:~$ locate org.eclipse.core.resources | grep history
/some/path/to/org.eclipse.core.resources/.history/24/109601fa0cd800101a3dcfaf52c523eb
/some/path/to/org.eclipse.core.resources/.history/24/e077e68009d7001017b898f7b25b1cbb
/some/path/to/org.eclipse.core.resources/.history/25/9095cb8d2bd7001017b898f7b25b1cbb
/some/path/to/org.eclipse.core.resources/.history/26/40fa905e2bd7001017b898f7b25b1cbb
/some/path/to/org.eclipse.core.resources/.history/27/80aeb1582bd7001017b898f7b25b1cbb
/some/path/to/org.eclipse.core.resources/.history/2a/20efb2cb11d800101a3dcfaf52c523eb
/some/path/to/org.eclipse.core.resources/.history/2a/80914b200ed800101a3dcfaf52c523eb
/some/path/to/org.eclipse.core.resources/.history/2d/f0acb5240fd800101a3dcfaf52c523eb
/some/path/to/org.eclipse.core.resources/.history/3/e060608410d800101a3dcfaf52c523eb
/some/path/to/org.eclipse.core.resources/.history/32/a0a33f8f0ad80010160af0d88658fae4
/some/path/to/org.eclipse.core.resources/.history/34/60374f474bd60010182b9a1ddb7c2773
/some/path/to/org.eclipse.core.resources/.history/34/c04a901b4ad60010182b9a1ddb7c2773
/some/path/to/org.eclipse.core.resources/.history/36/c0d19b430bd80010160af0d88658fae4
(…)

Third step

Go into the directory relative to your project. Specifically into the .history hidden directory. In this example I will search something about an android project:

pedro@pedro-laptop:~$ cd /home/pedro/workspace/android/.metadata/.plugins/org.eclipse.core.resources/.history/
pedro@pedro-laptop:~$ ls
0 13 1c 2 24 28 2f 33 38 41 48 4e 52 60 6a 71 7a 7f 84 88 9 9b a3 a9 af b2 b6 be c2 c7 ce da e6 ec f f3 fd 1 16 1d 20 25 2a 3 34 3a 43 49 5 57 61 6e 72 7b 8 85 89 91 9d a4 ab b b3 b7 c c3 c8 d2 db e7 ed f0 f7 10 17 1e 22 26 2b 30 36 3c 44 4a 50 59 63 6f 75 7d 81 86 8a 94 9f a5 ad b0 b4 b8 c0 c5 ca d7 e2 e8 ee f1 f9 12 18 1f 23 27 2d 32 37 3d 45 4c 51 5f 64 7 77 7e 83 87 8d 97 a0 a8 ae b1 b5 b9 c1 c6 cd d9 e3 ea ef f2 fc

Fourth step

Launching a ls, we will get a lot of directory names without any apparent sorting (I couldn’t figure at least). But we can sort them by date with this command:

pedro@pedro-laptop:~$ ls -tlahr

This command will show the directories from older to newest (oldest at top of the list, and newest in the bottom). The only thing we can do at this point is look into these directories, starting by the newest one. Maybe some directories are empty, in this case go to the previous one. Being lucky, you will find some directory containing some strange files named like a MD5 hash. Open them and check if they are what you are looking for:

pedro@pedro-laptop:~$ cd e2
pedro@pedro-laptop:~$ ls -lah
total 20K
drwxr−xr−x   2 pedro pedro 4.0K 2011-09-06 00:30 .
drwxr−xr−x 147 pedro pedro 4.0K 2011-09-06 00:54 ..
−rw−r−−r−−   1 pedro pedro 1.9K 2011-09-06 00:27 1036c7a60ed800101a3dcfaf52c523eb
−rw−r−−r−−   1 pedro pedro  824 2011-09-04 21:14 108c03632ad7001017b898f7b25b1cbb
−rw−r−−r−−   1 pedro pedro 1.3K 2011-09-04 21:25 505f6baf2bd7001017b898f7b25b1cbb

pedro@pedro-laptop:~$ gedit * &

If the force is with you, is possible to find your missing files. I got the force with me and I restored the work of my day! 😀

Luck & thanks to Dani who helped me making this story have a happy end!

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *