Geertjan's Blog

  • July 24, 2015

Reverting Deleted Files

Geertjan Wielenga
Product Manager

While checking the sources of the Cassandra/NetBeans integration into GitHub yesterday, something went very badly wrong and ALL the source files in my Maven project disappeared! Luckily I still had the Maven 'target' folder, which was untouched, I frantically searched for a Java decompiler online, decompiled the Java classes from the 'target' folder and then recreated my Maven project and eventually checked that in.

When I told Sven Reimers about this, he pointed out that in the IDE you can use the handy "Revert Deleted" feature. Let's say this is your project:

Now delete the Java source file you see above and right-click on the package (or anywhere in the ex-file's hierarchy) and choose History | Revert Deleted:

Hurray... there's the file again, the IDE still knows that the file existed:

Click OK above and your file is neatly returned to you, with all the content, and in the place, it originally had. Even after restarting the IDE, you'll still be able to do the above. Where is all this information stored? In the NetBeans cache directory (which is different to the NetBeans user directory), so, if you delete that directory, the information of deleted files will be lost and you'll not be able to revert again.

As a final step, go to the Options window and map "Revert Deleted" to a keyboard shortcut to make it an even faster process.

Of course, you should check things into a repository, e.g., GitHub. But normally, as in my case, you only put your GitHub repository together after you have created something significant enough to commit. If something, whatever it is, goes wrong during that initial process, the above procedure is extremely powerful, of course, and absolutely essential in these kinds of dire circumstances.

Join the discussion

Comments ( 1 )
  • ehsavoie Friday, July 24, 2015

    This feature has saved me a lot of time :o)

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.