196

I'm looking for a way to see my local history changes.

Kind of the equivalent way in WebStorm:

Enter image description here

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
Idan Dagan
  • 10,273
  • 5
  • 34
  • 41

7 Answers7

115

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:

  1. Add the history folder to your .gitignore file.
  2. Change the history folder location in the chosen plugin configuration.
  3. Configure the Visual Studio Code search to ignore the history folder.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BBacon
  • 2,456
  • 5
  • 32
  • 52
  • Thanks! but `local history` not works with temp files. temp files mean files which are open via FileZilla FTP client. This extension works with open workspace/folder. – Rahul Dadhich Jan 07 '20 at 10:04
  • 1
    @RahulDadhich I think plugin will only cover the VS code part, FileZilla and FTP client are outside VS code is I am not wrong? – Yash Tibrewal Nov 23 '20 at 12:49
96

it's pretty simple, just open a file and check timeline tab

Tip by: S P Sharan

Also if you have deleted a file, you can just create an empty file with the same name and the timeline should be populated once more!

enter image description here

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
Adán Escobar
  • 1,729
  • 9
  • 15
  • 7
    this was my life saver! I did a git checkout to another branch but without commiting the changes on the current branch. When i checked out the previous branch, my work was gone. I was able to restore the individual files I had changed using VS code's timeline feature. – DrMaxB Jul 20 '22 at 19:50
  • 7
    DUDE! Thank you so so much for this answer. `git reset --hard` removed my week's worth of work. I'm talking 1000s of line of code that got wiped out. And I almost gone into heart attack! But I happened to stumble upon here, not losing hope. And this feature is luckily installed by default. This thing saved me!!! – Waleed93 Aug 04 '22 at 23:11
  • 2
    And that saved my time to code again – tacqiya Jan 03 '23 at 12:52
  • 2
    I'm not sure why this answer is buried below two much longer ones, it should be at the top. – Ben Watson May 04 '23 at 09:57
  • 2
    Also if you have deleted a file, you can just create an empty file with the same name and the timeline should be populated once more! – S P Sharan Jul 12 '23 at 11:34
74

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.

local history settings

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)

Timeline local history commands menu

Mark
  • 143,421
  • 24
  • 428
  • 436
  • @dirkenstocks Everything in the answer is new. What you are referring to is git commit history, this has nothing to do with git. – Mark Mar 25 '22 at 18:00
  • 1
    See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_66.md#local-history – Mark Mar 25 '22 at 18:25
  • 2
    I've seen TIMELINE down there but hadn't checked it out. I just accidentally overwrote my entire site and thought I lost an entire's day of work, but the Timeline reverted every single file back to the previous state! Unfortunately the database can't be recovered, but having all the files back is a huge relief!!! – Gavin May 19 '22 at 20:45
  • thanks a lot save my 2 days of work – Arslan Ahmad khan Apr 01 '23 at 02:11
39

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.

micnil
  • 4,705
  • 2
  • 28
  • 39
18

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.

jabacchetta
  • 45,013
  • 9
  • 63
  • 75
  • Thanks for writing this up. Nothing against the two options listed; it would be preferred if VS Code would have native support this functionality. Preferably as an extension as not to bloat the IDE for those who don't have a use for the feature. – Rockin4Life33 Aug 07 '19 at 16:28
1

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.

-4

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Badri
  • 1
  • 1