Reputation: 872
I'm interested in the backup mechanics provided by VS Code. "Crash" includes both sudden power outages and handled exceptions. As examples of what I mean,
Upvotes: 18
Views: 37414
Reputation: 11
I found versions of recent edited files in C:\Users<username>\AppData\Roaming\Code\User\History
Upvotes: 1
Reputation: 4046
Brief answer to the question "How does Visual Studio Code recover data after a crash?":
VSCode runs a "Hot exit". In my experience it's pretty reliable. When it runs, it creates a copy of all unsaved files that were open in the tabs of a VSCode window (they call the window an Editor).
VSCode saves these copies in a Backups directory. It also generates a list of paths to the Editors that contained unsaved files.
You can reopen a previously open Editor in VSCode and see your backed up files.
To list the Editors that were open when Hot exit ran
using Terminal on MacOS
cat $HOME/Library/Application\ Support/Code/Backups/workspaces.json`
alternative using jq for a more readable list
cat ~/Library/Application\ Support/Code/Backups/workspaces.json | jq '.'
using Terminal on Linux
cat $HOME/.config/Code/Backups/workspaces.json
using Powershell on Windows
gc %APPDATA%\Code\Backups\workspaces.json
To browse the Backups directory
code $HOME/Library/Application\ Support/Code/Backups/
To Reopen the Editor you want, with the previously open files in the same tab order
code {{ folderUri from workspaces.json }}
I often forget what directories I had opened before VSCode quits/crashes, and the menu to "open recent" from within VSCode doesn't indicate which Editors have unsaved files. For that need the workspaces.json list that VSCode generates seems irreplaceable.
Hot Exit
VS Code will remember unsaved changes to files when you exit by default. Hot exit is triggered when the application is closed via File > Exit (Code > Quit on macOS) or when the last window is closed.
Upvotes: 4
Reputation: 872
According to https://code.visualstudio.com/blogs/2016/11/30/hot-exit-in-insiders,
The way hot exit works is to periodically make backups of unsaved files. If VS Code happens to crash, a backup restore will occur the next time the folder is opened.
On Windows, the backup folder is C:\Users\<username>\AppData\Roaming\Code\Backups
.
As for the period between backups, I haven't found anything.
Upvotes: 13