search
HomeDevelopment ToolsVSCodeLet's talk about the historical storage strategy in VSCode

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!

Let's talk about the historical storage strategy in VSCode

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

Lets talk about the historical storage strategy in VSCode

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 (default 10s).

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

Lets talk about the historical storage strategy in VSCode

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.

Lets talk about the historical storage strategy in VSCode

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!

Statement
This article is reproduced at:掘金社区. If there is any infringement, please contact admin@php.cn delete
Best Practices for Writing JavaScript Code with VSCodeBest Practices for Writing JavaScript Code with VSCodeMay 15, 2025 pm 09:45 PM

Best practices for writing JavaScript code in VSCode include: 1) Install Prettier, ESLint, and JavaScript (ES6) codesnippets extensions, 2) Configure launch.json files for debugging, and 3) Use modern JavaScript features and optimization loops to improve performance. With these settings and tricks, you can develop JavaScript code more efficiently in VSCode.

Use VSCode to perform version fallback operation of codeUse VSCode to perform version fallback operation of codeMay 15, 2025 pm 09:42 PM

In VSCode, you can use Git for code version fallback. 1. Use gitreset--hardHEAD~1 to fall back to the previous version. 2. Use gitreset--hard to fall back to a specific commit. 3. Use gitrevert to safely fall back without changing history.

Use tips and recommendations for the VSCode plug-in marketUse tips and recommendations for the VSCode plug-in marketMay 15, 2025 pm 09:39 PM

To better utilize the VSCode plug-in market, first use advanced search functions to filter the plug-in, secondly install and uninstall the plug-in, and finally make full use of the plug-in functions and maintain them regularly. 1. Use keywords and advanced search functions (ratings, downloads, release dates) to filter plugins. 2. Click "Install" to install the plug-in, and click "Uninstall" to uninstall the plug-in. 3. It is recommended to use Prettier, GitLens and LiveShare plugins, and regularly review and update the plugins to optimize performance.

An effective way to resolve Git commit conflicts in VSCodeAn effective way to resolve Git commit conflicts in VSCodeMay 15, 2025 pm 09:36 PM

Handling Git commit conflicts in VSCode can be effectively resolved through the following steps: 1. Identify the conflicting file, and VSCode will be highlighted in red. 2. Manually edit the code between conflict marks and decide to retain, delete or merge. 3. Keep branches small and focused to reduce conflicts. 4. Use GitLens extension to understand code history. 5. Use VSCode to build-in Git commands, such as gitmerge--abort or gitreset--hard. 6. Avoid relying on automatic merge tools and carefully check the merge results. 7. Delete all conflict marks to avoid compilation errors. With these methods and tricks, you can handle Git conflicts efficiently in VSCode.

How to manually install plugin packages in VSCodeHow to manually install plugin packages in VSCodeMay 15, 2025 pm 09:33 PM

The steps to manually install the plug-in package in VSCode are: 1. Download the .vsix file of the plug-in; 2. Open VSCode and press Ctrl Shift P (Windows/Linux) or Cmd Shift P (Mac) to call up the command panel; 3. Enter and select Extensions:InstallfromVSIX..., then select .vsix file and install. Manually installing plug-ins provides a flexible way to install, especially when the network is restricted or the plug-in market is unavailable, but attention needs to be paid to file security and possible dependencies.

Environment configuration for running Ruby code in VSCodeEnvironment configuration for running Ruby code in VSCodeMay 15, 2025 pm 09:30 PM

Configuring the Ruby development environment in VSCode requires the following steps: 1. Install Ruby: Download and install from the official website or using RubyInstaller. 2. Install the plug-in: Install CodeRunner and Ruby plug-ins in VSCode. 3. Set up the debugging environment: Install the DebuggerforRuby plug-in and create a launch.json file in the .vscode folder for configuration. This way, you can write, run, and debug Ruby code efficiently in VSCode.

Efficient way to install VSCode plug-in in batchesEfficient way to install VSCode plug-in in batchesMay 15, 2025 pm 09:27 PM

An efficient way to install VSCode plugins in batches is to use command line tools. The specific steps include: 1. Export the plug-in list: run code--list-extensions>extensions.txt. 2. Bulk installation of plug-ins: Run catextensions.txt|xargs-n1code--install-extension, so that plug-in configurations can be easily synchronized between different environments.

View Git history and changes in VSCodeView Git history and changes in VSCodeMay 15, 2025 pm 09:24 PM

How to view Git history and changes in VSCode include: 1. Open VSCode and make sure the project has initialized the Git repository. 2. Click the "Source Code Management" icon in the left sidebar. 3. Select "...(more options)" and click "Git:ShowGitOutput". 4. View commit history and file changes. 5. Right-click the file and select "Git:ShowFileHistory" to view the file change history. Through these steps, you can efficiently view Git history and changes in VSCode to improve development efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool