How to temporarily disable “preventing dirty write

2020-06-29 03:51发布

问题:

In my project, I've used some build/linting tools so they can automate force change my code based on some convention code styles but when I was running those scripts, vs code showed an error message: Failed to save "<file-name>": The content on disk is newer. Please compare your version with the one on disk.and continue to open the "Resolve to save conflict" tab. It seems to be annoying and not convenient for me.

So can you tell me how to disable this feature of VScode for a temporarily time?

回答1:

v1.42 is modifying this functionality including adding a setting so that the dirty file/save conflict notification can be disabled. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_42.md#ignore-save-conflicts

Ignore save conflicts

VS Code has a built-in mechanism to show an error when you try to save a dirty file that has been changed outside of VS Code or by another program (for example Git):

The motivation is to inform you that saving will overwrite the contents on disk even though the file was changed after the file became dirty. Clicking the Compare button lets you review your change along with the version on disk and either overwrite or revert the file.

In cases where you know that the changes on disk can be overwritten, there is now an Overwrite button directly on the notification. You can also configure files.saveConflictResolution globally or per workspace or file type to disable the notification altogether. The options are askUser (default) or overwriteFileOnDisk.