How do I undo my last discard of 2 uncommitted files? - intellij-idea

I accidentally discarded 2 uncommited files from my project. Is there any way to undo these changes/bring those files back. I use IntelliJ and VS Code simultaneously. MAybe some kind of editor cache or history where I can view last hour or so changes and copy those??

I found the answer. There seems to be no way to do this using just GIT. But an Editor like IntelliJ really helps. IntelliJ maintains a local history of changes you did (even uncommitted) and you can revert to any point in time (caveat it keeps history only upto few Days).
How To Revert
IntelliJ Project tab -> rt click there -> select Local History -> Show History. Just select the point in time you want to go and revert.
This Post will also be helpful for detailed steps
https://blog.jetbrains.com/idea/2008/01/using-local-history-to-restore-deleted-files/

If you created the file using IntelliJ, you're in luck since IntelliJ will track local history of edits and allows restoration. Right click the project in the project view, and select Local History. You'll be able to find the step in which the file was deleted, and will be able to roll it back with a right-click.

Related

intellij: is there selective undo feature as in emacs?

Basically, in emacs. we can undo changes only in a selected region. Its a a very useful feature. Wonder whether intellij has it.
No there isn't. The equivalent in IntelliJ is the local history. You can right click on a file, choose local history->show history. You can then see the changes made over time and select individual lines/sections to remove or reapply.

Intellij Idea: Override and update local changes

Is there a way to override/replace the local changes from the version controls (like svn, CVS)? In Eclipse, I can right click on the project->team->synchornize.. then it shows all changes comparing to the repository. Then, If I need to override the file, "update and override" option is there. Correspondingly, Is there such a way to replace local changes in a class or a package with one click in IntelliJ Idea?
(I found a way to compare incoming changes, then I had to get one by one changes to my local class files) . I use IntelliJ Idea community edition 15
For single file you can follow below steps :
a) Right click on file
b) Git ---> Show History
c) It will show a window in which you can see the history of changes, select a commit,right click on it. Select Get.
Link : https://intellij-support.jetbrains.com/hc/en-us/community/posts/207743285/comments/207412185
If I understand the question right, I think you need to revert your local changes then update from the remote. You can do this at a class or package level, or on the whole project.
I think it is going to be an two way process.
Revert the changes (Ctrl+Alt+Z).
Update the project (Ctrl+T).
Choose the project(if you have multiple files changed), right click -> GIT -> Compare with branch(select the branch which you want to override your changes) -> it will show the differences it detected -> click "Get" icon, it prompts "Some files were locally modified" -> choose "Overwrite Modified Files"
But sometimes it doesn't work well.
Another simple but dangerous way is to use git command:
git fetch --all
git reset --hard origin/master
(Then all your local change will be lost)

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.

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

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.