Add support for local history
Closed this issue ยท 66 comments
I would love to be able to see my local history for a file like you can do in intelliJ.
That would be amazing. Jetbrains has probably the best local history support. There are a couple of extensions for VS Code but they aren't as convenient.
please add this option please
I m afried of Git, and this story make me more afreid of using it.
THIS THING DELETED 3 MONTHS OF WORK!!!!
#32405
single programers we don t need all the git complexity.
+1 (just few mins ago, wanna discard some changes in just few files... discarded all unstaged files...)
Can anyone please suggest - "How can I see my local file history changes in VS code like we can check in eclipse IDE? Sometimes we do changes a lot in single file before commit and this feature can be really handy to check entire day's changes in one file. I have checked few plugins like "Local History" but the changed files keep on adding in my git changes section and changed file numbers keep on increasing. I doubt if I am using it correctly. Please suggest best plugin or options for it. Thanks
For reference, there is an extension, but it's not nearly as powerful as what's offered in IntelliJ/WebStorm.
Examples of features that I'd like to see if this were to be implemented:
- Being able to add checkpoints (local commits). This is the IntelliJ equivalent to adding tags to your history. There is another extension for that here, though.
- Being able to support local history when the files are moved/renamed.
- Being able to revert more than just edits (e.g. deletes, moves).
This feature set also has synergy with #43555, #52844, and #9390.
This is something that would be super helpful. even just to be able to save undo across sessions would be amazing.
Here's a horror story. I had all my files tracked in Git and began writing code for a new feature that used an API at the end of a file, so my workspace had uncommited changes. Because I had to wait for approval for more API quota to continue developing and testing my code and because my code wasn't yet commit worthy, I continued work on other projects and forgot I had uncommited changes in that repository.
A few days later I was experimenting with some VS Code features and I needed to purposefully create some linting errors in a file to test it out, so I opened that same repository and randomly deleted a few lines at the top of the file I had been working on a few days before. I mistakenly thought I could just "discard changes" in the Source Control tab and Git would bring my file back, reinserting the lines I deleted. I closed the file, losing the ability to undo (cmd+z) the deleted lines. As I was ready to reverse the deleted lines, I hopped onto the Source Control tab and only seeing the deleted lines at the top of the file (I did not look at the Ruler on the right hand side to see I had more uncommited changes), I pressed "Discard Changes".
A few days later my request for API quota was approved and I reopened the file. As I scrolled to the end of the file my jaw dropped and I started replaying this cute little story in my head, trying to understand out how the hell had I figured out a way to permanently delete my own work.
TL;DR
Local history would have saved me from having to spend a few minutes (but it could have been hours or days) rewriting permanently lost code.
I would love an ETA on this feature and a comment on what's blocking it from being shipped.
I would love this feature! ๐
+1
This feature is useful
Any update about this feature
+1
Today i stopped using VS Code after 4 years and switched to IntelliJ. THIS IS THE REASON WHY. I love VS Code, but a editor without local history is gabrage.
I just lost 30 file of refactoring because a commit issue - probably wasnt VS Code(probably husky), but it leaks local history.
VS code should add this feature ASAP otherwise sooner or later, developers find other IDE to work Because we all do mistakes and high chances of losing our work in the absence of this feature.
Team Explorer does let you view history for any changed files, but I don't see how to use it for a file that hasn't been changed...
Just now, after I git reset hard, I found all files I didn't staged was lost. It's so frustrating my day work just go away.
I had the problem that Prettier commit pre hook got stuck and i lost the files
I oppose this feature. For the reason that if am editing a file that I don't want the history tracked (e.g. with passwords or other secrets) I dont want vscode to store that information elsewhere in a magical/non-transparent way. I support a standard extensions that a user can opt into.
With respect to those who have experienced data loss, I think that's just part of what you need to deal with. I've lost data before for foolish rm commands or overwriting unstaged git changes. It sucks. But it's the behavior I expect from the tool and the responsibility i take when I use these low level capabilities.
I oppose this feature. For the reason that if am editing a file that I don't want the history tracked (e.g. with passwords or other secrets) I dont want vscode to store that information elsewhere in a magical/non-transparent way. I support a standard extensions that a user can opt into.
With respect to those who have experienced data loss, I think that's just part of what you need to deal with. I've lost data before for foolish rm commands or overwriting unstaged git changes. It sucks. But it's the behavior I expect from the tool and the responsibility i take when I use these low level capabilities.
Hey Dylan. Please don't mistake the desire for control over your own data for opposition to an enormously useful feature like local history. "The status quo being part of what we have to deal with" is not a good argument - we can solve both. Cheers ๐ฅ
I only realized there was no such a feature after I accidentally git reset hard in a wrong repo....
Great idea, done a little disservice by the (over) emphasis on data loss. Recovering from such is a handy side-effect, but not I think the primary motivation. Anyone who's used Intellij's local history (or emacs' undo-tree IIRC?), knows that having fluent nonlinear access to previous states of a file is an ergonomic master-stroke.
Everday i thing about back to phpstorm because two reasons, file history and search / search and replace, vscode simple perfect on the all anothers aspects
just pressed 'y' instead of ctrl+y, and lost a whole bunch of progress I had decided to redo. local history would have been a life saver here
https://marketplace.visualstudio.com/items?itemName=xpo.local-history
A new Local History extension for VSCode. It only backup the diffs instead of whole file when saving. You guys can use it while waiting for VSCode Local History official feature.
@cuongthm thanks, but it's another extension that uses a folder inside the specific workspace / project folder where you are working on, while I'd prefer something similar to what Netbeans does, which is putting all history info inside a IDE's folder.
It would also be nice to have a feature to clean history older than a certain date!
BTW I found https://marketplace.visualstudio.com/items?itemName=lihdd.vscode-line-history, what do you guys think about it?
I made two changes but wanted to commit only one.
Then i have to erase the part that I don't know any to commit but keep it in local changes, after commit i have to rewrite that part again to continue work.
With local history that was just a patch away
.
This is one of the features of intellij I miss. I would appreciate a native approach to this as well.
please!
This feature would bring VSCode to another level.!!!
It is MUCH needed.
I'm relatively new to VSCode, but people have been telling me it's the best way to do microcontroller work. It also has the easiest way to compile and deploy Marlin firmware (3d printer and laser engraver controller). There's something wrong that I did in the last few hours, so I wanted to check through the changes. There's no edit history?!!!
Even Notepad++ and vim have backups/edit history. I've always done well with simple editors on complex projects. I assumed that anything this big and feature rich would already have it available. I don't use it much, but when I do, I expect it to be there.
I see everyone saying xyz.local-history. That's installed now, but that functionality should have already been in VSCode. Installing it now doesn't help me with today's problem.
@JWSmythe this deficiency is recognized almost unanimously. I know you have good intentions, but this issue does not need more confirmation. What it is missing is a solution. If you cannot implement this or sponsor someone to do it, thank you for waiting patiently in silence like all other users.
Would you prefer me to just comment [bump], rather than saying why I agree? And, why complain about me and not the other 3 bumps this week? You could have patiently waited in silence until it was just fixed, rather than cluttering the comments with useless text.
Would you prefer me to just comment [bump], rather than saying why I agree?
What I would have preferred is for you to record your support in a way which does not trigger notifications.
And, why complain about me and not the other 3 bumps this week?
I recognize that my comment seemed to imply that you were the only one at fault here. I do not think that is the case and I apologize for that. That being said, your comment was the longest. It does contain information which could be useful prioritizing this issue. I just happen to think that this issue's importance is self-evident, and the hundred users who support this request every year are enough proof of that, so I would be most surprised if any comment which doesn't help implementation (or mitigation) would speed up resolution at this point.
You could have patiently waited in silence until it was just fixed, rather than cluttering the comments with useless text.
This issue is not a bug. VScode may not meet your expectations, but that behavior is not a defect.
i use this extension since 1 year without issu
https://marketplace.visualstudio.com/items?itemName=xyz.local-history
I am a newbie and i want to work on this. Do I have to replicate the features of https://marketplace.visualstudio.com/items?itemName=xyz.local-history or what extra needs to be done to make it native?
Hopefully it will be as perfect as intelliJ's local history
@kieferrm, @bpasero hi I want to work on this, how to go about it
I am thinking of replicating from https://github.com/JetBrains/intellij-community/tree/bd84401e970ff91b6e232bb129972fb5861c4ee5/platform/lvcs-impl/src/com/intellij/history
but I am new to the world of open source and would love some guidance
@kieferrm, @bpasero hi I want to work on this, how to go about it
I am thinking of replicating from https://github.com/JetBrains/intellij-community/tree/bd84401e970ff91b6e232bb129972fb5861c4ee5/platform/lvcs-impl/src/com/intellij/history
but I am new to the world of open source and would love some guidance
Have you looked here? https://github.com/microsoft/vscode/wiki/How-to-Contribute
A first version of "Local History" is now available to play with in our insiders build: https://code.visualstudio.com/insiders/
Anytime a file is saved, a new entry appears in the "Timeline" view. Local history entries can:
- compare to others or the file
- be restored
- deleted and renamed
In some cases we are able to tell the semantic change behind a save, e.g. when you run a refactoring and then the label of the entry will try to reflect that.
Since the timeline view does not provide a way to show all history entries, a separate command is there to view and restore any history entry that exists:
New settings are introduced to:
- enable/disable local history
- configure the maximum number of entries per file
- configure the maximum file size for a file to be considered for local history
Happy for feedback, please give it a try. Feel free to file issues too, but keep in mind existing issues.
Great news, thanks for that! Just a curiosity: what's the filesystem location of the files that are created to keep that history? And, is there a way to keep it clean at some point (either manually or automatically)?
I wanted to learn how to build that :(
@antariksh17 sorry for that. this was a rather involved change, but I am happy to answer any questions that you might have for how I added this via #145136. Typically I would try to look for issues that have the related label applied for where we ask for help, please see https://github.com/microsoft/vscode/wiki/How-to-Contribute#where-to-contribute
what's the filesystem location of the files that are created to keep that history? And, is there a way to keep it clean at some point (either manually or automatically)?
That depends on how VSCode is run:
- local desktop client with local workspace: local file system
- local desktop client with remote file system backed workspace: remote file system
- web client with remote file system backed workspace: remote file system
- web client with non-file-system-backed workspace (e.g. vscode.dev): IndexedDB in the browser
When stored in the file system, there is a folder called History
in the folder User
that is stored at the user-data-dir
, which depends on the OS you are on. That is the same location where e.g. also backups go or UI state.
As for cleaning up:
- entries can be manually deleted one by one from the timeline view
- oldest entries are automatically removed when the configured limit is reached
- there is a command to remove all entries across all files:
Not sure you are missing another way of cleaning up entries?
Can I make some suggestions? when comparing previous version with current, Could support fast append block content to another?
Please cast your vote at #25887
@bpasero Thank you very much for your excellent work.
I made a feature request here
Timeline - save the backup file relative to the original file
#145321
I have two more requests, but I could not open a new ticket (github gave me error 500!), so I will post them here:
Timeline - lists all the files which are saved in the backup folder
I hope we can have an option to see all the files which are saved in the History
folder, so we can cleanup orphan files and have a summary of our history timeline.
orphan files = when I delete or rename a file, its backups will remain in the History
folder inside user-data-dir
folder.
Timeline - track renamed files
when I rename a file inside vscode, its timeline is lost. I hope it can be tracked when renamed so it keeps the same timeline.
thank you.
Timeline - lists all the files which are saved in the backup folder
The command "Local History: Find Entry to Restore" gives you a list of every file that has local history entries. From there you can drill into the individual entry. If you have the "Timeline" view visible, you can delete individual entries. I know this is a bit rough from a UX point of view and I think #95332 needs to land in order for the timeline view to show the full set of all local history entries.
I am open for suggestions how to improve the "Find Entry to Restore" picker. It would be easy to add a button into the picker to remove entries from the picker.
Timeline - track renamed files
Yeah, that is on my list to look into, if I cannot get to it, I will file an issue for it.
The command "Local History: Find Entry to Restore" gives you a list of every file that has local history entries.
cool, I did not know that this option keeps track of deleted/renamed files too, nice.
I am open for suggestions how to improve the "Find Entry to Restore" picker. It would be easy to add a button into the picker to remove entries from the picker.
yes a button to remove an entry will be useful, or maybe a button to open the folder where the backup of a specific file resides, which will serve for other purposes (like deleting the content or do a grep search), because actually the folders names inside History folder use a hash, and it is impossible to decrypt that hash because of the Bitwise left shift used I think.
Yeah, so the location of a history entry is actually a hash of the full original path so that we have a fixed-length unique location for each file. Within the location, each entry is a random 4-length name with the original extension. As a sibling there is a entries.json
file that contains the original file name and some metadata, e.g.:
{
"version":1,
"resource":"file:/Users/bpasero/Desktop/project/file.ts",
"entries":[
{
"id":"4oXJ.json",
"timestamp":1647520366982
},
{
"id":"DEnq.json",
"timestamp":1647523809834
},
...
]
}
Feel free to file individual issues for the things you ask for, then we can proceed in those issues and discuss them there.
We will ship this feature as part of our April release next week. You can use our insiders builds to benefit from the feature today: https://code.visualstudio.com/insiders/
The test plan item #145461 covers its capabilities, so feel free to give it some testing and report issues back.
Some new things added over the past days:
- track renames of files that are under active local history
- a new setting
workbench.localHistory.mergePeriod
to merge entries over a specific period of time - a more prominent filter action in the timeline view to enable/disable local history entries (or git entries)
Existing issues are labeled timeline-local-history
If anyone has a better idea for how to call the workbench.localHistory.mergePeriod
setting, feel free to reach out:
The way it works is:
- you save and immediately a local history entry is created (so it is not a delay or timeout)
- any new entry that is within 10s to the last entry will replace that entry (so it is more like a debounce)
Some suggestions so far from the team are to call it frequency
or debounce
.
call it frequency or debounce.
interval
also !
and more synonyme !
https://www.thesaurus.com/browse/frequency
https://www.thesaurus.com/browse/interval
https://www.thesaurus.com/browse/delay
Yeah that site is really helpful, I use it a lot. I think interval
might be a bit misleading because as a user you might think that now a local history entry is created every 10s
even without user action. For example setInterval
in JavaScript installs a function that will run every <n>ms
.
I vote for debounce
for the sake of accuracy. Interval
, frequency
, and delay
don't really capture what it is.
Another idea I had was mergeWindow
. window
seems to describe a time span and so merge
would occur in a certain time span.
Though window
is a bit of a overloaded term, especially in an application that has a lot of window
UI settings.
I vote for the word merge too. how about mergeChanges
@badrelmers the setting itself is a number
as seconds though, so I would like to have some kind of reference to time in the settings key.
yes. then why not mergeChangesInterval
?
A few more suggestions:
saveDebounceInterval
<- my current preferencemergeDebounceInterval
It seems to be impossible to go back to the old behaviour, which is to have a single timeline item called "uncommitted changes". This makes it very hard for me to see what I have changed since the last pull, without painstakingly going through each individual timeline item and memorising the full diff between each version.
Storing local history is very useful, but could we have a switch to easily toggle between showing:
- All individual local saves
- All uncommited changes together (i.e. merged)
Turning off the new local history feature in workspace settings seems to show just the git timeline without any information about uncommitted changes.
Uncommitted changes are accessible from the SCM changes view:
The decision to remove the entry from timeline was discussed in #145723
This should be something you can toggle between. And if you turn off local history then it should definitely still be shown.
Uncommitted changes are accessible from the SCM changes view:
I did not test the proposal, but it would be useful to tag history entries in relation to SCM. If the latest committed state was flagged, that would facilitate the use case of @jacrosby (as long as that entry is still in history...)
There is currently no relation between SCM entries and history entries, they are 2 independent providers of timeline entries.
I want to thank everyone involved so much for this feature.
Last week I was able to recover 3 days of work after hitting delete on samba share directory that contained a symlink. photorec and ext4magic couldn't restore the files from my ext2 fs partition.
I figured its all gone when I did a final grep through the vscode-insiders-server folder and found the all of the code in perfect condition. I was so happy!