In Intellij IDEA how do I reload file content's from disk? - intellij-idea

In vim I can type :e and reload a file's contents from disk overwriting any changes I've made. It's a nice way to reset in case I've gotten lost or just want to undo all my changes. This obviously doesn't take into account any kind of refactoring, I just want to nuke all changes to buffer. Not even closing and reopening a tab will work.
How do I do this with Intellij IDEA? I'm using Intellij IDEA Ultimate 13 and I've disabled any kind of auto save.

File > Synchronize (Ctrl+Alt+Y)
It will load the file from the file system. If you have unsaved changes, it will ask if you want to discard them.

⌥⌘Y - Synchronize for Mac users

What I do in a similar situation:
Simple - Ctrl+Z, Ctrl+Shift+Z many times to quickly navigate the editing history
VCS rollback - either for the whole file or for the area being edited (by clicking green areas on the left)
Local History. Well, yes, for you case it's granularity is not sufficient, so first might be an option
There is also an option to put a label into Local History if you need to rollback to a specific point in time.
For those who use autosave - it is being triggered when code editor loses focus. So doing Alt-Tab during long editing without compiling or running the code makes sense.

Open the file in another editor, make an insignificant change and save it. PHPStorm will ask you what to do because the file system and in memory copies of the file have diverged. Click "Load File System Changes".
Note, I was unable to use my undo history as it had become corrupt.

Since what I want isn't really possible I wrote an extension to do it for me:
https://github.com/btipling/DiskRead/
I'll add it to the Jetbrains plugin repository, it's called "DiskRead".
I wrote a blog post about how I created this if anyone is curious.

Related

PhpStorm "Save as" open new file

This always catches me out, but it appears to be another PhpStorm only quirk. Normally when you "Save as" a document, it will open the new file. This happens in all Adobe products, all Office products, and every other app I can think of... except PhpStorm.
So many times I've forgotten about this quirk and started working over the old file, thinking it was the new one. It's most frustrating.
Is there a way to change this behaviour?
Is there a way to change this behaviour?
Unfortunately no.
Save as is basically a shortcut for Save and then Refactor | Copy.
https://youtrack.jetbrains.com/issue/IDEABKL-332 I guess (based on "duplicate" tickets)
General suggestions (Captain Obvious):
Invoke Refactor | Copy on desired file before making changes in it (so it will sit deep in your mind that the currently edited file will keep changes)
Use Local History to rollback unwanted changes in old/original file.

Intellij undo history size, not much?

I like to be able to undo basically several hours of work in a file. I am unsure how to configure this.
In IntelliJ settings, the clipboard settings I have tried with are 999 and 9999 and 99999 but it still too short on undos.
How can I increase this?
In Intellij settings the clipboard settings I have tried with are 999 and 9999 and 99999 but it still too short on undos.
I've failed to see what "clipboard settings" have to do with the "undo limit" (or with "undo" at all). Care to explain?
Local History is definitely the way to go here as it works across sessions, files, and whole folders -- you can undo very complex operations in one click (e.g. replace/refactor in multiple files).
In any case: if Local History is to complex or you are a hardcore person who prefers to hit Ctrl + Z quite a few times in a row instead of few clicks with Local History, you can increase undo limit (which is 100 steps by default). For that:
Open Registry (Help | Find Action... and type registry)
Find undo.documentUndoLimit entry and set your limit to a higher number (e.g. 1000).
P.S.
IDE restart may be required.
Actually, based on JetBrains Docs, for changing undo limit you should act just like below steps:
click Help on the top menu:
Click on Find Action:
Type Registry and open first result:
On the opened window file undo.documentUndoLimit and undo.globalUndoLimit and change it to number what you want.
HINT: After change you should close your JetBrains IDE and open it again.
The "Maximum number of contents to keep in clipboard" setting has nothing to do with undos.
In fact, there is no configurable "undo history size" setting in IntelliJ. See this support issue:
For rolling back complex code changes gone awry, a far better option is to use the local history.
Local History is available under the menu "VCS" -> "Local History" -> "Show History". The feature is explained as:
IntelliJ IDEA tracks any changes you make to your source files or any other file, as well as the changes that affect a directory’s content and structure. This feature will protect you from any accidental losses or modifications, even if made by other applications outside IntelliJ IDEA. Setting version labels is also available. Any time you can inspect the history of either a particular file or directory and rollback to any of its previous versions.

Temporarily Remove Or Hide Code in Intellij

Is there a way to temporarily hide or remove a file from Intellij? I used to work in c# and I remember there was some way in visual studio to temporarily remove a project from the build then add it back later. I am just trying to figure out what parts of code are necessary for certain features.
This is a perfect use case for git stash.
If you're not using a git repo, hit Ctrl+Shift+A and type "Create Git Repository", then hit enter to initialize git tracking on your current project.
Initially, you'll want to add your important files to git. Hit Alt+1 to navigate to the Project View, then select all the files.
In order to add a file to git, press Ctrl+Alt+A, you should see the filename turn from red to green. It is now being tracked.
Now you'll want to make your first commit. Hit Ctrl+K, and IDEA will guide you through this.
Finally, once everything's all checked in, you can start messing around a little. If you make a few changes, say delete a file, and want to temporarily revert to the last commit, hit Ctrl+Shift+A, then "Stash". Select "Stash changes", write a little message for yourself, and you'll immediately jump back to the last commit.
Now say you want to go back to those changes you stashed. Hit Ctrl+Shift+A again, type "Unstash" then select "Unstash changes". Find the stash, check "Pop stash" and hit Enter.
This is a pretty common workflow for temporarily saving, removing and reverting changes in Git. You can read more about git stash here, and version control on IntelliJ IDEA from Martin Balliauw.

IntelliJ - not asking if I want to save a file

I'm new to the IntelliJ IDE. In the past I was working with Visual Studio or Eclipse.
In those IDEs there was an asterisk * above the name of the file which has been modified.
But in IntelliJ with the default configuration I can't see if the file is modified. What's more the file is saved automatically when I change focus to another window.
I've found some options under Settings -> IDE Settings -> General -> Synchronization:
Synchronize files on frame activation
Save files on frame deactivation
Save files automatically if application is idle for...
After unchecking all that options the file is not saved automatically every time I change focus to another window, which is good. But still I can't:
see if the file is modified (no asterisk)
decide if the file should be saved when I'm closing it (IDE doesn't ask for that)
And when I'm closing IntelliJ file which has been modified is saved without even noticing.
Do you know what can I do to change how IntelliJ behaves?
After unchecking mentioned options go to:
Settings/Editor(IDE Settings)/Editor Tabs:
Check "Mark modified tabs with asterisk"
On 2019.3 Ultimate it's under:
Settings/Editor/General/Editor Tabs:
Mark modified (*)
The exact Save feature like eclipse is not available in IntelliJ.
Because IntelliJ IDEA has the ability to change so many files
simultaneously in large refactoring actions, and change them without
ever opening them, single file saves don't make very much sense. In
recognition of this, IntelliJ IDEA reserves the right to save any of
your files literally whenever it wishes. It's actually quite nice to
never have to worry about your file's save statuses, once you get used
to it.
"What if I don't like some changes I made, and want to roll them
back?", I hear you say. Well, for that IntelliJ IDEA includes this
amazing feature called the Local History. Every time it saves your
files, IntelliJ IDEA actually saves a diff of your file from it's
previous state, and saves that as well. You can see the entire edit
history of your files (going back some number of days), see the
changes you've made, and roll back any change. It rules triumphantly,
and more than makes up for the temporary disorientation caused by lack
of single-file save.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206336279/comments/207351939
To show an asterisk when a file is modified: open Settings (CTRL+ALT+S), switch to Editor > General > Editor Tabs and select the Mark modified tab with asterisk checkbox.
To remove autosave, uncheck: Appearance & Behavior > System Settings > Save files on frame deactivation

Submit Eclipse Project on Perforce

I have a noob Perforce question. I got my perforce plug-in on Eclipse working(for both Java and C).
I have no problems "opening" my perforce stored projects on Eclipse.
Scenario 1:
Whenever I want to change code, I open the project on Eclipse and right-click on it and go to "team" and check out, make changes and then submit. Works fine. But even after that I see a tick mark(indicating check-out) on my perforce screen.
Scenario 2:
I just open perforce code as Eclipse project and make changes(If read only, it prompts and asks if i have to allow write and I say yes). I make changes and save. It doesnt ask for submit. Also if I now open the code on Perforce screen, I already see the new changes made.
Scenario 3:
Just on a Perforce screen, if I check a file out and don't make any changes, I obviously dont want to submit as there are no changes. In this case, how can i "disable" check-out so that my fellow programmers dont think i'm working on it??
Scenario3:
So here are 2 ways i consider a good usage of the plugin:
Use Revert Unchanged Files:
Before you begin development of a feature, checkout the entire tree/branch that your changes will be concentrated around in future. You can do this by right-click the relevant package in package explorer. Once you want to submit, Project->Right-click->Team->Revert Unchanged Files. Now, you can submit your changelist.
This approach stands very useful if you know you will be editing a lot of files or replacing files.
Ofcourse, others can see that you have checked out the files.
Enable Auto checkout:
Incase you are going to make few changes, you should enable autocheckout. This will checkout the file when you begin to make edits. Eclipse->Preferences->Team->Perforce->Enable support for workbench edit..
detailed explainations here. Its a good idea to have this enabled always as it checks out on demand.
However, this does not monitor the filesystem so and code/libs you replace outside of eclipse are not checked out.
For Scenario 3, you can change a workspace option to prevent submitting unchanged files:
SubmitOptions: reverttunchanged
If you have a file checked out (open for edit), others will be able to see that. I guess I'm not clear on why you check a file out if you don't intend to modify it?
If you are going to setup this way and are also using the desktop client, I recommend the following steps in the desktop client:
1.) Open your desktop Perforce client
2.) Click “Connection” on the global menu
3.) Select “Edit Current Workspace…”
4.) Under the “Advanced” tab select “allwrite”
5.) Click Apply, then OK