7

VS Code crashed without saving - how do I get back the code contents?

  • I've already checked, but didn't find the file:
    %AppData%\Code\Backups
    
JW0914
  • 9,096
Aknoks
  • 81

3 Answers3

17

You can recover your projects from the VS Code cache either via:

  • Command: Ctrl+Shift+P
    Local History: Find Entry to Restore

  • Directory: History
    Each file has a directory, and within each directory there are different versions of the same file
    # Linux:
      ~/.config/Code/User/History
    

    Windows:

    %AppData%\Code\User\History

    MacOS:

    ~/Library/Application Support/Code/User/History

Trigus
  • 321
5

I'm surprised the missing part hasn't been mentioned:

  • @Trigus's answer accounts for those contents that belong to a file, however the temporary contents that haven't yet been saved can be found within the Backups folder:
    # Linux:
      ~/.config/Code/Backups
    

    macOS:

    ~/Library/Application Support/Code/Backups

    Windows:

    %APPDATA%\Code\Backups

JW0914
  • 9,096
Colliot
  • 327
0

If you don't have backups, look in the Recycle Bin for possibly finding a deleted version of the file.

You could also set Windows Explorer to show hidden files and look in the folder where the file was last located. You may find there a version of it with a mangled name.

Look also in the temporary files folder (if in doubt run in the Command Prompt the command set TEMP).

harrymc
  • 498,455