Using Local History to restore deleted files

Suppose you have accidentally deleted a file from your project, and want to have it back. Sure, you can restore it using the file system, but IntelliJ IDEA suggests a better way to do it, without leaving the IDE.
This is where IntelliJ IDEA’s local history on the project or folder level comes to help, preserving all modifications that affect the nested files, including the changes to the contents and to the file tree in general. Each change is marked with its time stamp, revision, and action description. Unlike version control that keeps track of the committed revisions only, the local history preserves all local changes you make as you edit, compile or test, during few days (it is up to you to define how long you want this history to be). This “personal version control” will help us restore the deleted file.
In the example below, a file Lost.txt has been deleted from the FontChooser project. Let’s try to restore it. Go to the Project tool window and right-click the project node or just a folder, where the file used to exist:

On the context menu, choose Local History, and click Show History on the submenu:

The local history view for a project or folder shows you everything that you have done during the last few days. In the Action column of the lower part of the dialog box, select the action you want to roll back. In our case, this is the “Deleting” action. So doing, the upper part of the dialog box shows the tree view of changed files.
If you want to restore the deleted file only, regardless of the other changes that have been done since then, you can select the file Lost.txt in the tree view and click the Revert button on the upper toolbar. The file will be restored silently.

A different situation occurs, if you want to restore the deleted file and the whole project or folder state as of a certain revision. In this case, place the cursor on the revision prior to the “Deleting” action, or on the action itself, and click the Revert button on the lower toolbar. If the other files have been changed since the “Deleting” action, you will be prompted that the other changes will be reverted too. Look again at the Project view – our file is here:

Technorati tags: ,
This entry was posted in Tips & Tricks and tagged . Bookmark the permalink.

23 Responses to Using Local History to restore deleted files

  1. Ken Orr says:

    This feature saved me! Our source control system devoured one of my files and left not a trace of it behind. IntelliJ’s local history saved me, as it new the file was there before, and let me salvage its contents.

    This is a fantastic feature!

  2. Irina Megorskaya says:

    Hi Ken !

    Thank you very much for your positive feedback :)

  3. Mike D says:

    Hey! Major thanks for posting this — you just saved my entire week of “uncommitted” work. And to think the IT guys said I was SOL. You rock!!

  4. Rob says:

    Hello,
    I have a disaster recovery situation I’m in the middle of, and wondering if this feature might help me out. I actually lost several project directories, whole and complete. Am trying a number of things at the moment, but I’m du’ing against the .Intellij10 directory and I see a phat system/caches directory; I’m convinced my local history is just locked up in there.

    Is there any way I can access this cache? I’ve started and quit IntelliJ only once since the incident; when I loaded it up (of course) it couldn’t load my last project because it didn’t find it; and it wasn’t available in “Reopen projects->” list…

    Any thoughts/help would be appreciated!

    Rob

  5. Someone says:

    Thank you for this amazing feature!
    Just recovered two days work…

  6. Alexander says:

    My source directory was completly removed! And I get all code back with this amazing feature… THANK YOU!

  7. Frank says:

    Now this is what I call a *seriously* butt-saving feature. Thank you. Bleary eyed and tired I accidentally wiped out a directory of important files, and then synched with my production server, which of course wiped the files out on the server. I spent all day trying to recover them with search and recovery programs. I was just about to give up and jump off a cliff when I poked around and found the local history. I recovered everything and restored close to a month’s worth of work.

    I learned two lessons:

    1) PHPStorm rocks.
    2) Only idiots work without some sort of versioning system.

    Thank you for adding this excellent feature.

  8. mike says:

    Thanks for this! I also accidentally removed a whole day’s work with a misplaced git reset, and thankfully, I was able to restore everything with this feature.

  9. hangtwenty says:

    this just saved a week of work. thank you so much.

  10. Suseika says:

    Helped me to restore a couple of files that appeared to be untracked by Git after a sudden outage. Praise IDEA!

  11. Oleg says:

    You are the best, thanks for this option, it helped me :)

  12. Nicholas Pickering says:

    Local History has triumphed again! Without it, I would’ve lost 3 days worth of work. Thanks, IDEA.

  13. ed austin says:

    Fantastic!!!
    Saved a whole evenings work that would have been real hard to replicate!!!
    You guys rock!!

  14. Calum says:

    I love this feature. Just saved me from redoing a few hours of work. Thanks!

  15. Ahrar says:

    great feature :) Thanks

  16. Shaun says:

    SAVED! awesome feature!

  17. Itay says:

    Great solution,
    Thanks

  18. grub says:

    Saved me two days!
    Thank you!

  19. gheorghei says:

    A nasty commit to SVN wiped out a fat import script AND its output. Two days of work, and I only had hours until the life-changing demo of our product.

    Thank you, thank you, thank you!

  20. dmitiryl says:

    Woups… saved my evening)

  21. Russ says:

    This feature just saved my work, my project, my marriage, and my life.

  22. Mateo says:

    Years and years of saved work!
    You rock guys!!

  23. Randy says:

    Thank you for this! Accident delete the file and save my time! I should have commit the files first.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">