How to recover a deleted file in Eclipse

Today I accidentally deleted a file in Eclipse. I didn't even know I did it until I ran my code. I am not even sure how I deleted it. My best guess is the current focus was on the project explorer and some strange key combo sent the file to the netherworld.

Eclipse, as you probably know, does not use the Windows 'recycling bin'. As luck would have it, the file was long, complex, just freshly debugged and not yet in version control.

I was able to recover the file by using the Restore from Local History option located in the context menu inside the project navigator.

"What?!?! I thought that only worked for files, not directories..." , you might say. I thought the same thing. Thankfully Eclipse is smart enough to know that when humans are behind the keyboard, expect the unexpected.

Try it and see for yourself.

Disclaimer: Not responsible for damage resulting from deleted files. Delete your files at your own risk.The posting and use of this information is governed by the laws of Uzbekistan. All legal proceedings must be filed in person on the third Tuesday of July at 1342 Uzbek Lane, Tashkent Uzbekistan. Accidentally deleting files can result in one or more of the following horrible incidents:

  • You could miss deadlines
  • Your boss could fire you
  • Your computer may stop functioning
  • Your computer might function incorrectly
  • Your computer could burst into flames
  • All the beer in your refrigerator could disappear
  • A puppy could die

Comments
Subversion, Subversive/Subclipse and the Team menu are also pretty useful for making sure you don't lose files or changes. ;)
# Posted By Stephen Moretti | 1/18/08 9:02 AM
I have always wondered if there was a way to do this.
# Posted By david buhler | 1/18/08 10:00 AM
@steven

Yeah, I am a large fan of subversion. I use it on all my personal projects and recommend it to all my clients. What I meant in the post above by "just freshly debugged and not yet in version control." was that while the file was looking really good, I had not committed the file as it was just yet. I do not line checking in versions that do not run.

I am, however, open to ideas. At what stage of developing a component do you commit?

DW
# Posted By Dan Wilson | 1/18/08 3:21 PM
Restore from Local History works like a charm. Except when you accidentally delete an entire project and also check 'also delete contents'.
I did this the other week, and there's no coming back from it.. :-(
# Posted By jax | 1/21/08 4:33 AM
> At what stage of developing a component do you commit?
>
Depends....

If I'm working in a branch I tend to hold on to changes until they are working. This is because most times branch changes are pretty small bug fixes and minor functional additions, so it doesn't actually take that long to make those changes anyway.

If I'm working in the trunk, I try to remember to submit in every couple of hours. Usually when I've added some discrete bit of functionality (whether it works or not). I've had issues in the past where I've wanted to go back to a revision in the local history only to discover that its outside of the local history range. I tend to work on the premise that trunk, while it should work, is mostly likely going to be broken.
# Posted By Stephen Moretti | 1/21/08 5:18 AM
Thanks man! You saved my life!
# Posted By Roland | 2/28/08 6:10 AM
Hi,
Thats really made for me most useful, unfortunately number of files get deleted I was really totally sad, whether is it any way to get back my very suspecious files but after googling ur response given me a very very useful way to recovered it very easily. After all just I wanted to say Eclipse is really a powerful tool.

Very very thanks to you for your such valuable posted response....
# Posted By Ajay Kumar | 5/16/08 3:07 AM
Really greatly helpful. I saved around 48 hrs work with this feature.
# Posted By Eswar.Annapureddy | 5/20/08 1:27 AM
Thank you so much, I only knew the context menu for an existing file. You saved me about 18 hours of work!!!
# Posted By Markus | 6/27/08 11:17 AM
Thank god for this feature :D I'm new to svn and I didn't realize that revert deletes any packages that aren't in version control yet. So when I clicked revert to fix some minor issue, I lost a package with about 50 hours of work invested in it. It took me 30 minutes to find this solution and now I'm saved from the wrath of my superiors :] :]
# Posted By Greg | 7/8/08 3:27 PM
Hell yeah, your tip saved the day, thanks!
# Posted By im a huge fan | 8/29/08 5:00 PM
Thank you soooo much. I was looking everywhere for how to get my file back. You are the MAN!
# Posted By JB | 9/11/08 6:20 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001. Contact Blog Owner