Search code examples
visual-studio-codeintellij-ideapycharmwebstormjetbrains-ide

Recover deleted code file using editor or IDE (not saved in Git)


How can I recover a file that was deleted outside a code editor/IDE such as VS Code, PyCharm, GoLand, WebStorm or IntelliJ, if it wasn't committed to Git recently?

Please add any other solutions in comments.


Solution

  • Limitations of Git and backups

    Using Git is strongly recommended, but it's easy to not commit frequently, so it may not have your latest changes.

    Automated backups are good, with the same problem of frequency.

    Editors and IDEs

    Please suggest more options in comments

    Some editors or IDEs have automatic local file history features that track every save and work well to recover deleted files, including:

    • JetBrains IDEs (PyCharm, GoLand, WebStorm, IntelliJ, etc): find the deleted file in the Project pane then use the local history feature to restore the file - details in this guide

    Always test this works in your environment, since some tools only work in limited scenarios.

    Editors/IDEs with some limitations:

    • VS Code has a local file history feature in the Timeline view since March 2022, but this may not always work to restore a deleted file:
      • If the deleted file is still open in a tab in VS Code, it can be restored, apparently even if you restart VS Code
      • Opening the deleted file again with code deleted-file.py didn't show any history, so the file could not be restored