5

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
    
2

3 Answers 3

12

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
    
5
  • You saved lots of my time. Thank you. Commented Feb 11, 2023 at 15:43
  • On macOS, it's at ~/Library/Application Support/Code/User/History.
    – s3cur3
    Commented Oct 19, 2023 at 16:31
  • Saved me plenty pain, once in the windows folder with all the randomly named folders I made this bash command to find python files with a phrase I knew was in the file ("bootstrap"), for easy searching. grep -rl "bootstrap" ./**/*.py
    – Issung
    Commented Oct 24, 2023 at 7:42
  • wrong. this is for saved versions of the file. not the latest unsaved version.
    – starball
    Commented Dec 15, 2023 at 8:57
  • Just so you know, this works and save my file!! No wonder there are people walking oblivious to how many others in this life they've made smile without ever seeing their smiles.
    – Amineze
    Commented Jul 14 at 14:55
1

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .