I have used WebStorm from JetBrains for almost four years now. It's a fantastic IDE for many reasons, but one of the best features is that it saves versions of files outside of version control. So if you accidentally delete files or lose files before they are saved by your version control system, WebStorm has a copy of them and there are visual diff tools to use. This feature has saved me on more than one occasion.
For Visual Studio Code, is there some feature/plugin that will auto-save copies of files as they change? Will Visual Studio Code save the files to some central location, or perhaps in the .vscode folder in the local workspace?
The feature in WebStorm is available from Local History → Show History from a folder or file. Here is an article about it:
Using Local History for code changes tracking
The view looks like:
You can go to menu File and choose Auto Save.
You can enable auto save with these methods:
Check the Auto Save item in the File menu
Go to Settings, search for auto save, and select the auto save option (afterDelay)
Auto save description in Visual Studio Code documentation
Yes, Visual Studio Code can auto-save changes on files as you make changes. It also allows you set a delay for how long to wait before saving the file.
Here's a link that should help you with that.
Or a shortcut you can simply navigate to your Visual Studio Code settings, and add the following to your settings.json file.
{
...
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
...
}
This will instruct your editor to autosave after a 1000 ms delay. You can set the autosave option to onFocusChange to autosave whenever you move your cursor away from the current text area.
There's a package called Local History that can be used to save a backup of your files outside version control.
You should check that out.
As of March 2022 (version 1.66), Visual Studio Code has a built-in feature called Local History that automatically creates commit-like versions of your files on every save.
It is enabled by default, but you can double check the setting workbench.localHistory.enabled to make sure it is enabled in your project.
From the reference:
Each local history entry contains the full contents of the file at the time the entry was created and in certain cases, can provide more semantic information (for example, indicate a refactoring).
From an entry you can:
Compare the changes to the local file or previous entry.
Restore the contents.
Delete or rename the entry.
The saved local versions are accessible from the Timeline section in the File Explorer tab.
Also, ensure you add .history to your .gitignore file, so Visual Studio Code doesn't track every change made to a single file as changes made to multiple files. This can be a problem and make your files changed so large even though it's a single file or a few files you made edits to.
Related
I'm looking for a way to see my local history changes.
Kind of the equivalent way in WebStorm:
Visual Studio Code now offers this in the Timeline view. See Mark's answer.
Or alternatively, if you want a plugin to give you similar functionality, for example:
Checkpoints
Or the more famous:
Local History
Some details may need to be configured because the Visual Studio Code search gets confused sometimes because of additional folders created by this type of plugins. To fix this, you can:
Add the history folder to your .gitignore file.
Change the history folder location in the chosen plugin
configuration.
Configure the Visual Studio Code search to ignore the history folder.
Local File History
Local history of files is now available from the Timeline view.
Depending on the configured settings, every time you save an editor, a
new entry is added to the list:
Each local history entry contains the full contents of the file at the time the entry was created and in certain cases can provide more semantic information (for example indicate refactorings).
From an entry you can:
compare the changes to the local file or previous entry restore the
contents delete or rename the entry
see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_66.md#local-history
Local file history is being actively worked on and is in the Insiders' Build v1.66. The results will be available in the Timeline view.
Here are the current applicable settings:
Workbench > Local History: Enabled
Controls whether the local file history is enabled. When enabled, the
file contents of an editor that is saved will be stored to a backup
location and can be restored or reviewed later. Changing this setting
has no effect on existing file history entries.
Workbench > Local History: Max File Entries
Controls the maximum number of local file history entries per file.
When the number of local file history entries exceeds this number for
a file, the oldest entries will be discarded.
Workbench > Local History: Max File Size
Controls the maximum size of a file (in KB) to be considered for local
history. Files that are larger will not be added to the local history
unless explicitly added by via user gesture. Changing this setting has
no effect on existing file history entries.
And these commands:
timeline.toggleExcludeSource:timeline.localHistory
workbench.action.localHistory.compareWithFile
workbench.action.localHistory.compareWithPrevious
workbench.action.localHistory.selectForCompare // compare any 2 entries
workbench.action.localHistory.compareWithSelected
workbench.action.localHistory.delete // delete this entry
workbench.action.localHistory.deleteAll // delete all entries of all files from local history
workbench.action.localHistory.open
workbench.action.localHistory.restore
workbench.action.localHistory.restoreViaEditor
workbench.action.localHistory.rename // rename this entry
New global commands have been added to work with local history:
workbench.action.localHistory.create: create a new history entry for the active file with a custom name
workbench.action.localHistory.deleteAll: delete all history entries across all files
workbench.action.localHistory.restoreViaPicker: find a history entry to restore across all files
A bunch of new settings have been introduced to work with local
history:
workbench.localHistory.enabled: enable or disable local history
(default: true) workbench.localHistory.maxFileSize: a limit of
file size to create a local history entry (default: 256kb)
workbench.localHistory.maxFileEntries: a limit of local history
entries per file (default: 50)
workbench.localHistory.exclude:
glob patterns for excluding certain files from local history
workbench.localHistory.mergeWindow: interval in seconds during which
the last entry in local file history is replaced with the entry that
is being added (default 10s)
it's pretty simple, just open a file and check timeline tab
I built an extension called Checkpoints, an alternative to Local History. Checkpoints has support for viewing history for all files (that has checkpoints) in the tree view, not just the currently active file. There are some other minor differences aswell, but overall they are pretty similar.
Basic Functionality
Automatically saved local edit history is available with the Local History extension.
Manually saved local edit history is available with the Checkpoints extension (this is the IntelliJ equivalent to adding tags to the local history).
Advanced Functionality
None of the extensions mentioned above support edit history when a file is moved or renamed.
The extensions above only support edit history. They do not support move/delete history, for example, like IntelliJ does.
Open Request
If you'd like to see this feature added natively, along with all of the advanced functionality, I'd suggest upvoting the open GitHub issue here.
right-click the file and select Show History.
Other day I lost my git changes because I've clicked that graphic undo option of Git.
This option saved me so I could get back my code.
There isn’t any option in Visual Studio Code to see file history. If you are using Git, then you can use Visual Studio Code extension Git History to see the file changes after each commit and compare with previous commits.
I'm running into a small but weird annoyance that seems to be happening to other people, too (for example, check out the revision history of SEDE). I have a SQL Server 2008 database project in Visual Studio 2010 that works properly. When I go to commit/checkin to source control, I'm told that my DB project's .dbmdl file has changed, even when I've made no changes to the project!
I'm not sure if the changes are triggered by building my solution (which also includes an ASP.NET MVC application and a unit test project) or by simply opening the DB project, but this is getting kind of annoying and is creating clutter in source control.
Is it possible to stop these changes from occurring, or get rid of the .dbmdl file whatsoever?
If you delete the .dbml file, it is rebuilt without errors or warnings, so I think it's just a cache file for references, intellisense, etc. I'm going to exclude it from source control.
I believe Visual Studio serializes the dbmdl file every time the project is opened. The only possible work around would be to keep the project open.
See related question here. The .dbmdl file is unique per user (and some kind of cache, as said above) and so the right solution is indeed to exclude it from source control.
So I have a word template that I am trying to populate within my wpf application. It works fine during development. However, when I try to edit the file after publishing/installing the application it no longer has the folder/files that were used in the development process.
What steps do I need to take to have files present after installation to manipulate, create, or delete files?
Right-click the file in VS Solution Explorer, then in file properties set Copy To Output Directory to Copy Always
Add that template as content in your solutions. You will find this from properties.
When I have an SQL Server Database project (.sqlproj) in Visual Studio solution, I notice that that particular project always gets built every time I build the solution even though there is no change in the project files.
This is inconsistent with normal C# project (.csproj) that only gets built when there is any file that changes.
I have tried cranking up the msbuild output verbosity, and it seems to always build that project without special reason.
Is there a reason why .sqlproj is always built? Is there a way to make it build only when file changes?
MSBuild has the opportunity to make Incremental Build. The main idea of that is the following:
MSBuild attempts to find a 1-to-1 mapping between the values of these attributes. If a 1-to-1 mapping exists, MSBuild compares the time stamp of every input item to the time stamp of its corresponding output item. Output files that have no 1-to-1 mapping are compared to all input files. An item is considered up-to-date if its output file is the same age or newer than its input file or files.
I don't know which targets are inside the *.sqlproj file, so you need to determine does it ever uses that technology, and if it do use - you need to examine which inputs and outputs involved, and try to clarify it by yourself, what is going on with them under the hood.
I'm running into a small but weird annoyance that seems to be happening to other people, too (for example, check out the revision history of SEDE). I have a SQL Server 2008 database project in Visual Studio 2010 that works properly. When I go to commit/checkin to source control, I'm told that my DB project's .dbmdl file has changed, even when I've made no changes to the project!
I'm not sure if the changes are triggered by building my solution (which also includes an ASP.NET MVC application and a unit test project) or by simply opening the DB project, but this is getting kind of annoying and is creating clutter in source control.
Is it possible to stop these changes from occurring, or get rid of the .dbmdl file whatsoever?
If you delete the .dbml file, it is rebuilt without errors or warnings, so I think it's just a cache file for references, intellisense, etc. I'm going to exclude it from source control.
I believe Visual Studio serializes the dbmdl file every time the project is opened. The only possible work around would be to keep the project open.
See related question here. The .dbmdl file is unique per user (and some kind of cache, as said above) and so the right solution is indeed to exclude it from source control.