Revert file changes in editor to disk-saved version
I have hard time getting used to many basic missings in phpStorm's project and file management.
One of them.
Is there a way to revert changes in the file being currently edited to the disk-version? This is a basic feature of most editors and IDE's out there but not here, in what is purportedly the most advanced IDE for php.
From the Local changes dialog there are random moments in time when the IDE got it's "head" to make a step in this list, but there is no way of knowing the exact place where the file was last saved/loaded.
The goal is to close the file/editor_tab without saving any of the changes and the next time I open the file from the project tree, to have it fresh from the disk-version.
This elementary situation seems impossible in phpStorm, how's even that possible?!
Please sign in to leave a comment.
Hi there,
You can use Local History to revert your file (or whole folders/batch operations) to previously saved versions.
Thanks, but my question was different.
I know Recent History dialog(s). I called it Recent Changes but I meant Recent History diffs.
In there there is no indication of which entry follows the LAST file save (or when the file was loaded from disk in case of no saves after that).
Ideally there should be a button or key combination for something like "Revert file in editor to last saved version". In essence this is reverting all recent changes up to the point when the file was last saved or loaded from disk, whichever comes last. You get the point.
We somehow can put up with the fact there are no plans to introduce confirmations on file-close, but there Should be a way to easily revert to the current disk-saved-version of the file in its editor tab.
I know this is a long-time discussion and issue, but at least some options for us who work the way all other programs work, would be tremendously nice.
Well ... there is an action called "Reload from Disk" (based on description it shoul dfit your need) -- you may assign custom shortcut to it (it has none) at "Settings | Keymap".
P.S.
It will ask for confirmation before reloading.
----
I was referring to Local History (official name) not "recent" -- don't know why you call it that way.
"Recent Changes" is a bit different thingy.
Not sure what you mean here: every entry there represents previous save. Simply speaking: the aforementioned "Reload from Disk" would just discard current file in memory and re-read it from disk; at the same time the Local History allows you to go back in time even further.
The aforementioned "Reload from Disk" sounds like the one you need.
"every entry there represents previous save."
- Obviously this is not the case and what you say is misleading. I made two changes to a file, with some minutes apart in time each. This results in two states in Local History window.(Ok, Local History is what I talk about until now).
Then I open the file in another program and I can see it doesn't have these two changes in place (the disk version that is to say).
Currently I have two states in Local History fo the open file in phpStorm with no way of knowing which of the steps to use to revert the editor to the current disk version.
About the "Reload from Disk", I see it in Keymap settings, but I couldn't find it in the interface (menus, windows, submenus etc.). Is it only available as a keymap?
Is there a way to assign a macro or something, so Ctrl+W (my current assignement for Close-ing the editor) would execute Reload From Disk, and close file, or I should rely on Autohotkey.
Thanks.
Don't know -- it seems to be working OK for me here (as far as I can judge from my experience). Possibly I'm working differently or IDE is configured differently (auto-save/auto-refresh etc) -- not sure at all.
The only extra entries I see it's when I do batch operations (e.g. "Replace in Path") which affects bunch of files and I did not pressed "Save" yet... In other occasions the entry represents actual save (be it manual or automatic).
On another hand -- possibly you are correct as I'm using Local History very rarely (I'm not fan of "messing around" in working code (prefer separate test files) and rarely editing wrong file by mistake).
Yes, not all actions (especially those that are rarely used) are not listed in main menu. But you can easily add it to the menu or toolbar if desired -- just look at "Settings | Appearance & Behavior | Menus and Toolbars"
Up to you -- macro will do (you can record such macro and then assign any shortcut to it).
Thanks again.
Added some actions to the toolbar at least.
The macros functionality doesn't seem to work right though. At least not with these two actions: Reload From Disk (having to confirm a dialog box), then Close document.
Activating this macro executes only the first step, but does not close the document. Going to Edit Macro shows the two actions though.
Anyway, will try with AutoHotKey. AHK solved numerous problems like this for me.
By the way, I'm "messing around" with a local copy of my projects. Not production. And it's not about editing wrong files. It's about basic choice to safely close a file without saving changes. It happened many times to close a file and thinking it is closed for good (no confirmation and the asterisk on the tab is barely visible), but the IDE saving the changes on exit. Contradicts any other software on Earth we are used to and this is a real problem. I've not switched totally to phpStorm, and things like these are real problem for me and anyone I work with here.
But I will try the AHK approach and see if we can put up with that.
Maybe it's because of the confirmation dialog (macros gets interrupted or something)...
TBH -- macro support in all IDEA based IDEs is very basic and weak as for my liking (lots of unexpected bugs, I would say).
It's a matter of working habits / work process I guess.
It was unusual and weird to use for first few weeks for me as well (e.g. I've used to making changes in current file and then use "Save as" into another file where current file would remain unchanged) .. but after 1.5-2 months of using this IDE for all of my PHP coding (I still was using Dreamweaver for CSS/HTML at that time) it's all gone. And as it is right now I would safely say that it made my job easier and safer (latest changes are always remembered, even if I forgetting to click "Save" before running debugger/tests or just executing command in built-in terminal) -- it feels absolutely normal for me, at least for PHP/CSS/JS/HTML and alike.
At the same time I have no idea how I will behave if such behaviour would be introduced in other tools I'm using for coding (e.g. MS SQL Server Management Tools or Delphi) -- working habits there are different to what I've got here.
Therefore you may only see the benefits / getting used to this only after some time (few weeks/months/or actually never) -- depends on person and his habits.
I concur with everything you said.
But there is the main question - Why you (me etc.) should spend 1.5-2 months of confusion and getting used to this, If all that could be avoided with the proper 2-3 features that are not features for any other program. And whoever wants to choose to use it or not.
I really want to get used to this Because I admit this IDE has the best features and customizability etc. That's why I'm really stubborn to find a workaround for this lack or anything close. Because I see many many occasions in my workflow that I depend on this and to avoid disasters.
I'm already Ok with autosaving on exit - I keep my IDEs for weeks and months without restart, and usually I save everything before going out anyway, so the UPS could not be interrupted to automatically shutdown the OS and apps in case of power outage.
I found the Save individual file command already present in the IDE (after years of waiting and begging in numerous threads, assigned Ctrl+S to that), that's great.
Now it's only the closing of the file that should be worked around. I don't want to autosave everything when frame is losing focus for numerous reasons. But I want when closing a file, its changes to be saved or discarded totally, right away. I'll try to figure this out.
Thanks again for pointing me out to few solutions.
P.S. By the way I already encountered an issue (8.0.3). All autosaving options (4 total) are turned off in settings, but still the IDE made an unexpected save of the currently edited file. I couldn't reproduce it after that though. I was playing with the options in the current session, but when this happened I'm totally sure they were all off, I checkd twice after that. Maybe I should restart the IDE after making many changes in settings, maybe it didn't respect few of them right away, IDK.
Certain auto-saves cannot be turned off. To name a few:
The point about accepting new settings is something I didn't suspect. Also the File Watchers. The others were logical.
Certainly I applied new settings fairly often, that might be it.
The File Watchers is a nice feature, just tested it for scss (can replace my external Koala resident file watcher).
Another thing that is bugging me now is the lack of separate tree/file-list project display. FOlder tree on the top, corresponding file list on the bottom. Combined in one tree is too crowded. I know the Open symbol/class feature (very indispensable indeed, couldn't live without), but sometimes I can't remember the file/symbol name until I go to the folder, or when there are duplicates in different hierarchies. Got used to that view in my current ide. But I'll try to sacrifice this too. phpStorm has many and tempting features.
There is no such layout in PhpStorm.
Different things to try:
1) "Navigate | File ..."? BTW -- if you finish with "/" it will list all files in matching folders
2) Custom scope (instead of default "Project Files" -- see the top of Project View panel) -- it can limit folders/files displayed to those that match the pattern
3) "Navigate | Select In .. | Project View" -- to select currently edited file in Project View (that's if you do not like "Autoscroll from Source"). Useful if you want to open file that is located close to the current one.
This is all good.
The Custom scopes however need to be defined and named, I cannot search or filter quickly. The search on the other hand only highlights the items that match, not filter others out.
Ok, this I can live with somehow.
But Ok-ing the Settings dialog saves open files, why is that? It is very confusing. I don't understand why this behavior. Having few unsaved files in broken state, all auto-saving features are off, and I want to change a small setting, and boom - all get saved and now the local project copy is not working. And I cannot revert all open files to the state they had before that because 1) I cannot remember exactly which files I have changed after opening, 2) assuming I can identify which files I've changed, I cannot see which of the Local History states correspond to the previously saved versions (before my changes), 3) Even if it was possible, it would be a real pain to go through all these steps everytime I change the slightest setting in Settings.
I cannot believe this is happening in an IDE. I had all the good intentions to get used to all kinds of basic lacks in the software.. There are too much similar situations one has to constantly watch out for, and this potentially negates the arguments originally used all the time to justify the lack of these basic features.
Very very sad.
I don't really know what to suggest you here -- I simply do not have such problems.
Yes, it behaves just as you described .. but I personally simply have no problems with such behaviour, at all:
Quite possibly it's all because I'm working differently to what you have got used to and/or do not see a problem where yo do (different person -- different requirements).
----
If you want to learn more -- just go trough corresponding/related tickets -- you may read devs answers and ask your questions there (I don't really believe that those devs will be coming into this topic to answer your questions here -- it may happen, but very unlikely):
Thanks for taking the time (again).
You are right, most of the time my workflow is similar to yours. Working on 2-3-4-5 files at most, and saving regularly.
But there is situations when this behavior is obstructing or plain illogical (as in the case of Ok-ing in the Settings dialog). Ok, let's say I will not tinker often in Settings after the initial "burst" to tune everything to my liking.
I have to acknowledge that most other IDEs are just crap (apart from one - I have narrowed down other contenders to just one in my tests) and that's the only reason I still consider if I can find workarounds to these lacks in phpstorm and didn't ditched it yet.
I edit a file, go to the kitchen for a minute, come back, close the file thinking it was done (or by mistake), edit another file, then I totally forget about the first file being edited and not saved (but closed), then I see the project is not working as expected. Now I have to open dialogs with changed files, to reconsider what has been edited and done, etc. etc.. Or I may experiment within a file and wishing to close it without aving the changes. Close it thinking it is closed for good, then exit the IDE at some time (days after), and again, you have broken project. The situations are countless. It is about cases beyond the "normal" robotic workflow you/we follow "most" of the time. It's even incosistent with any other program in the world. That's why all use Ctrl+T for new tabs for example, and not everyone using whatever in his mind.
Having tons of good feattures, I don't understand why not adding an option for those wanting to confirm a file save or not save on close, etc. Make it optional, but provide it for thousands of developers that want it, and you will have many more customers and fans. It is really beyond me.
Anyway, enough ranting, I'm sorry for this. I was ranting in other discussions and tracked issues before. The single-file-save was eventually added at some point, after years of ranting. Why - because they saw it was requested, wanted, needed and... logical. A most basic feature. You see. :) MS added back the start button for the same reason. And this OS is enormous and full of complexities.
I'll keep experimenting, thanks again.