8

This has been asked regarding Windows, but not macOS.

(Yes, there's a comment on that question regarding macOS, but it's a comment and not an answer, so it's likely to be overlooked, and it's on a question about Windows, and to top it all off it's wrong.)

So, for sake of making (the correct version of) this information easy to find:

Where does VS Code store unsaved files on macOS?

iconoclast
  • 3,260
  • 6
  • 35
  • 38

2 Answers2

12

It can be found in a subdirectory of

~/Library/Application\ Support/Code/Backups

Note that the space above has been escaped with a \ character, so you can copy the path and paste it onto the command line.

If you want to put it in quotation marks, then you'll need drop \ character, and replace ~ with $HOME, like so:

"$HOME/Library/Application Support/Code/Backups"

On my laptop the subdirectory is named with a 13-digit number, inside of which is /untitled/. I would guess that the directory above untitled probably varies from installation to installation.

iconoclast
  • 3,260
  • 6
  • 35
  • 38
  • if you are using the VSCodium flavour it is located here: `"$HOME/Library/Application Support/VSCodium/Backups"` – DoRivard Dec 16 '19 at 16:10
  • At that 'Backups' folder location, you can also look at the `workspaces.json` file; it will list the nice directory path for each project directory which corresponds to the "hashed" directory names. If you go into each one of those and run `code .`, it'll bring up your unsaved files directly. – BrianC Feb 22 '20 at 00:02
6

Updated answer in 2022, for MacOS Monterey and VS Code version Version: 1.67.2 (Universal).

The path where I successfully recovered my 'otherwise considered lost in git rebase, uncommitted, unstaged' file is below:

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

To supplement anyone trying to figure out a way to search all files with a specific extension containing one of the keyword you remember, here is the command:

find . -name "*.extension" -exec grep whatYouRememberFromFile {} +

Or if you remember only the file name, here is a command that list all 'entries.json' files which will contain all history of the file in hash format

find . -name "entries.json" -exec grep portion-of-the-file-name {} +
PravyNandas
  • 161
  • 1
  • 2
  • I have both directories... does `History` keep a more detailed running history of changes? I'm not sure whether to change the accepted answer to yours or leave it as mine ... – iconoclast May 28 '22 at 04:13
  • Thank goodness for this answer! You just saved me from losing half a day of work. – Janosh Aug 04 '22 at 23:35