VSCode has added the function of retaining the local history of files. This article will talk about the history storage strategy in VSCode. I hope it will be helpful to everyone!

Updated VSCode yesterday and found that VSCode also added the function of retaining the local history of files. I recall that not long ago, in order to add a history recording function to Yank Note, I scratched my head and conceived a history storage strategy for a long time. I lament that if VSCode had been released a few months earlier, I would have had a reference. [Recommended study: "vscode introductory tutorial"]
But when I looked at VSCode's historical storage strategy: so crude?
VSCode’s strategy
The local history of files can be displayed in the timeline of VSCode 1.66 version. The effect is like this

For this function, VSCode has also added some configurations:
There are also new settings to work with local history:
workbench.localHistory. enabled- Enable or disable local history (default:true).workbench.localHistory.maxFileSize- File size limit when creating a local history entry ( default:256 KB).workbench.localHistory.maxFileEntries- Local history entries limit per file (default:50).workbench.localHistory.exclude- Glob patterns for excluding certain files from local history.workbench.localHistory.mergeWindow- Interval in seconds during which further changes are added to the last entry in local file history (default10s).
Right click on the history entry, there is a menu to find the file directly in the system manager A copy of a historical record.
It can be inferred that VSCode saves a file to a folder within a certain time window (default 10s) for each save/undo operation. Historical records are located through special file naming (retaining time information).
This is too rude, a file is just a version.
Typora’s strategy
Then let’s talk about Typora’s strategy that was investigated at that time. Typora has a very exquisite file history backtracking interface on macOS

It seems that it should use the system's "time machine" to implement version backtracking. So this feature is no longer available on Windows.
Yank Note’s strategy
The historical version I envision has several goals:
The most important goal is to try to avoid data loss.
Historical records should not occupy too much space. It is best to record incrementally.
In extreme cases, it is necessary to facilitate users to restore data.
Historical records should be able to mark and make notes
For the first goal, I hope to retain the user’s most recent edited version and not discard it. And Yank Note has an automatic saving function, so it has a second goal, not to take up too much space, and not to generate too many files. So the time window file saving strategy that I originally thought of, similar to VSCode, won’t work.
For the third goal, I don’t want to introduce custom formats, such as Git, or databases. Because if the user loses data and it is inconvenient to find the history records in the software (software is damaged, files are accidentally deleted, etc.), the user must be able to enter the history directory and retrieve the files.
Follow-up: A user accidentally deleted a document and the recycle bin could not find it, so he restored it through this method.
Considering the fourth goal, I finally chose to use zip files to save the historical version of the file, although it will consume a little computing performance in writing and reading history (more than 10 megabytes in size The file history is basically imperceptible), but the final effect is still very good.
Final solution:
Each document is hashed by the file name and path to spell out a zip package file name
Each time Write the file and write a new version of the file into the zip file
Change the name of the zip file simultaneously when moving and renaming the file
The maximum number of historical versions can be limited.
Version notes and tag information can be stored in the compressed notes field.
Usually when editing a file, due to the automatic saving mechanism, the difference between the current version and the previous version is very small, so in theory, a new version file is added to the compressed file, and the compression The overall file size increase should be very small. But later I discovered that this was not the case. Only then did I realize the characteristics of Zip file compression: each file is compressed separately and then packaged together. That is to say, when adding files to the compressed package, they will not be compressed together with other files.
In response to this situation, I adopted a two-compression strategy: the first time, I set the compression rate to 0 and only packaged it, so that the zip package contained the original information of the file. The entire packaged file is compressed once for the second time. Now the compression program can consider the overall information for compression, which achieves the purpose of "incremental update".
Write a script to test later. A file of ordinary length will only occupy 50KB if it saves 1000 versions.
After using it for several months, my history file directory only takes up more than 700 KB of space, and most of the history files in it are only a few KB in size. Looking back at VSCode, the history directory occupied 2M in the past two days.

Further
For historical storage, I also further thought about some preservation strategies
relatively At the last save time, retain:
- Every version in the past 10 minutes
- One version per minute in the past 1 hour
- Every hour in the past 24 hours One version
- Keep one version every day
- Marked backup
But it seems that it is not needed now. The current strategy is simple, each It also met my expectations.
For more knowledge about VSCode, please visit: vscode tutorial! !
The above is the detailed content of Let's talk about the historical storage strategy in VSCode. For more information, please follow other related articles on the PHP Chinese website!
How to enable EditorConfig support in VSCode?Jul 23, 2025 am 02:13 AMEnable VSCode EditorConfig support without complicated operations. The specific steps are as follows: 1. Install the EditorConfig plug-in (optional but recommended). You can search and install official plug-ins through the extension panel to enhance configuration recognition; 2. Create or add .editorconfig files in the project root directory to define code format rules such as indentation style, line break type, etc.; 3. Verify whether the configuration is effective. You can check whether the EditorConfig rules are applied through the right-click menu "FormatDocumentWith...", or use the command panel to run "EditorConfig:RecheckConfiguration" to reload the configuration.
How to set default formatter in VSCode?Jul 23, 2025 am 01:58 AMTo set the default formatting tool for VSCode, first select and install the formatting extension, and then set the default formatter through the command panel; secondly, configure the formatting rules in settings.json; finally, enable automatic formatting when saving. The specific steps are: 1. Install formatting tools such as Prettier, and set the default formatter through the command panel (FormatDocumentWith...); 2. Add the default formatter configuration for the corresponding file type in settings.json to ensure the configuration is synchronized; 3. Optionally, enable editor.formatOnSave and editor.format in settings.json
VS Code keybindings 'when' clause exampleJul 23, 2025 am 01:51 AMWhen customizing shortcut keys in VSCode, the "when" clause is used to specify the trigger condition. 1. Common conditions include: "terminalFocus", "editorHasSelection" (the editor is selected), "filesExplorerFocus||folderExplorerFocus" (sidebar focus), "inputFocus" (input box activation), "!terminalFocus" (non-terminal interface), etc.; 2. Group
What is the shortcut for Zen Mode in VS Code?Jul 23, 2025 am 01:43 AMZenModeinVSCodeminimizesdistractionsbyhidinginterfaceelementsandcenteringtheeditor.1.ActivatingitwithCtrl KZ(Windows/Linux)orCmd KZ(macOS)hidessidebars,panels,statusbar,andactivitybar.2.Userscanstilltoggleinterfaceelementsbacktemporarily.3.Exitusingt
What is the shortcut for command palette in VS Code?Jul 23, 2025 am 01:37 AMThe shortcut key to opening the command panel in VSCode is Ctrl Shift P (Windows/Linux) or Cmd Shift P (macOS), which can quickly access a large number of commands and functions. 1. After opening, enter keywords to filter commands, such as entering "indent" to adjust the indent settings; 2. No complete command name is required, partial matching is supported; 3. It can be used to install extensions, switch themes, configuration settings, etc.; 4. It is especially useful when new users or explore new functions; 5. Common errors are to accidentally press Ctrl P to enter file search; 6. Some extensions will also add commands to the panel; 7. Common commands can be fixed through custom shortcut keys.
How to create and use code snippets in VSCode?Jul 23, 2025 am 01:36 AMThe method of creating custom code snippets in VSCode is as follows: 1. Open the command panel (Ctrl Shift P or Cmd Shift P); 2. Enter "Preferences:ConfigureUserSnippets" and select; 3. Select the target language or create a new global fragment file; 4. Add code templates in the open JSON file according to the format, such as setting prefixes, contents and descriptions; 5. After saving, enter the prefix and press Enter or Tab to expand it. For example, you can create pybase prefix fragments at the beginning of a Python script, which greatly improves the efficiency of repetitive code writing.
VS Code peek definition shortcutJul 23, 2025 am 01:33 AMWhat is PeekDefinition? How to use shortcut keys? Can you customize it? 1. PeekDefinition is a function in VSCode used to view variables, functions or class definitions, and will not jump out of the current editing position; 2. The default shortcut key is Alt F12 (Windows/Linux) or Option F12 (Mac), and a window pops up next to the current code after triggering will display the definition; 3. You can enter the keyboard shortcut settings through the command panel, search for "PeekDefinition" and customize the shortcut keys, or add mouse operations; 4. This function is suitable for quickly understanding the context when reading large projects, and it is more efficient to use with Hover.
Where is the keybindings.json file in VS Code?Jul 23, 2025 am 01:32 AMTo find or edit the keybindings.json file for VSCode, you can operate it through the operating system specific path or command panel. The Windows path is C:\Users\\AppData\Roaming\Code\User\keybindings.json; macOS is /Users\/Library/ApplicationSupport/Code/User/keybindings.json; Linux is /home\/.config/Code/User/keybindings.json. If you are not sure about the path, press Ctrl Shift


Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.








