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

There are no comments for this entry.

Add Comment Subscribe to Comments

1/18/08 9:02 AM # Sez Stephen Moretti

Subversion, Subversive/Subclipse and the Team menu are also pretty useful for making sure you don't lose files or changes. ;)


1/18/08 10:00 AM # Sez david buhler

I have always wondered if there was a way to do this.


1/18/08 3:21 PM # Sez Dan Wilson

@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


1/21/08 4:33 AM # Sez jax

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


1/21/08 5:18 AM # Sez Stephen Moretti

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


2/28/08 6:10 AM # Sez Roland

Thanks man! You saved my life!


5/16/08 3:07 AM # Sez Ajay Kumar

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


5/20/08 1:27 AM # Sez Eswar.Annapureddy

Really greatly helpful. I saved around 48 hrs work with this feature.


6/27/08 11:17 AM # Sez Markus

Thank you so much, I only knew the context menu for an existing file. You saved me about 18 hours of work!!!


7/8/08 3:27 PM # Sez Greg

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 :] :]


8/29/08 5:00 PM # Sez im a huge fan

Hell yeah, your tip saved the day, thanks!


9/11/08 6:20 PM # Sez JB

Thank you soooo much. I was looking everywhere for how to get my file back. You are the MAN!


10/31/08 9:41 AM # Sez Joe Zack

I had the same problem and solution as well. I !swear! eclipse ate 3 of my files, I just wish I knew how to not repeat it.

Just had to empathize w/ you!


12/16/08 10:28 AM # Sez Sriram N

You made my day ! Thanks


3/4/09 8:16 PM # Sez natalie

man I love you! (and eclipse off course :)


3/29/09 12:17 AM # Sez Carlton Dickson

Mate, I love you as well! I know exactly how I did it...I was pressing ctrl + z (undo) thinking I was undoing changes in my source code but in fact my focus was on the project view (my files) and it was undoing the ones that I created...Eclipse should sort this issue out as I'm sure many have made this mistake and haven't been lucky enough to find this solution!


4/29/09 3:30 AM # Sez Dan Parker

OH MAN...you are a lifesaver!!!! I just checked my work into Dev and it said a file was missing...evidently I deleted it accidentally...first time for that one...THANKS for posting this!!!!!


11/9/09 9:40 AM # Sez Raghu

Thanks for the post, it was very useful.


11/10/09 2:41 PM # Sez Cristi

Yes, Carl is right! I second him on the CTRL + Z issue if pressed in the Navigator pane, and it's a "pane" in the arse cause it really does undo changes made at the file structure level (creation / renaming), which are very common tasks accomplished by a developer. However it does not undo the deletion of files, just as well as it does not magically redo the deleted files (by accidentally pressing ctrl + z) if you think of trying ctrl + y to restore.

In my opinion this is pretty critical (deleting files) and it should be simply fixed by showing a dialog box, similar to the one shown when you're trying to delete a file by pressing the "delete" key.


11/27/09 8:10 AM # Sez christian

you're a lifesafer, THANKS!


12/17/09 10:22 AM # Sez Anton

Thank you man! You've just saved 5 days of my life!


3/7/10 4:32 PM # Sez Some GUy

THANK YOU! THANK YOU ! THANK YOU ! THANK YOU! MUAH! MUAH! MUAH!


3/29/10 8:02 AM # Sez Stephen Steven

Thanks !


4/30/10 3:45 AM # Sez Pavan

Thanks a lot. Once again a life-saver.


5/3/10 3:25 PM # Sez DimOn

Hey man! You probably saved me couple days!! I'm sending you some virtual packs of beer!!!! :)


5/9/10 8:09 AM # Sez Schmuli

Thanks, with such a clear explanation, it's no wonder you're the first google result for "eclipse undo delete".


5/16/10 3:22 AM # Sez Sulagna Majumder

THANKS A LOT...............


5/17/10 1:04 AM # Sez sf

Aww, this was a really quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done.


5/18/10 9:47 AM # Sez Moi Aussi

Thank you. I agree there should be a redo of your undo though...


5/23/10 1:02 AM # Sez Carlos

You are a genius! I had just accidentaly -and idiotically- lost 25-30 hours of work. You saved my day. Thanks a million.

I'm more and more in love with eclipse every day.


7/9/10 10:19 AM # Sez Chilloutman

You are my HERO!! I love you man! You saved me about 3 days of work!


7/16/10 3:47 PM # Sez K

Found this page after rewrote the class I accidentally deleted but this will be helpful in the future in case of a mishap.

Thanks.


7/28/10 11:01 AM # Sez Jared

there is a bug in subversive where if you're checking in a file for the first time with some revisions it sometimes will delete the new file. This happened to me about 15 minutes ago with a file I put a good amount of work in to... and you saved my day. Thank you!


8/1/10 10:40 PM # Sez muosa

Thanks Man


8/10/10 2:21 PM # Sez Laurie

I almost slit my wrists while trying to figure out how to recover files I didn't even delete.

Thank you for this page!


8/14/10 1:26 AM # Sez digitalpbk

Phewww... thanks a loot for this ... I was blank for a minute when I accidently deleted the file I was working for 2 days ... !!!


Add Comment Subscribe to Comments