Using Local History to Restore Code Fragments or Deleted Files
Continuing our series on how2pro with IntelliJ IDEA, today we’d like to tell you more about a good old feature that can turn out to be a real lifesaver: Local History.
Unlike version control systems, which only keep track of the differences made between commits, local history offers much more. It automatically records your project’s revisions triggered by various events as you edit code, run tests, deploy applications, and so on.
Acting as your personal version control system, local history lets you restore deleted files, bring back separate changes, or roll back to any state of a file even if no version control is enabled for your project yet, or if an unwanted change was made after your last commit. It may also serve as a recovery source if your PC restarts unexpectedly before you can take any action.
The default retention period for local history is 5 days, but that’s configurable.
Let’s imagine you had made a ton of changes to a file since your last commit before you realized you’ve deleted a meaningful chunk of code. The undo action can’t help you here, because that change is too far away and you’ll be forced to discard other changes if you use it.
Local history to the rescue! Right-click anywhere in the editor and choose Local History | Show History or press Ctrl+Shift+A on Windows and Linux or ⇧⌘A on macOS and then type ‘local history’.
What you’ll see is a list of all saved revisions of the current file with a timestamp on the left, and the diff viewer on the right which displays the differences between each revision and the current state of the file.
Locate the piece of code you want to restore and simply click the chevron button (») to copy it from the left pane.
Restore deleted files
If you’ve accidentally deleted a file that was not under version control, select the folder that contained that file in the Project view and invoke local history for that folder.
Then select a revision that contains the file you want to restore, right-click that file, and choose Revert Selection:
You can learn more about local history from our documentation.
Local history is available both in IntelliJ IDEA Ultimate and in the free Community Edition. Download IntelliJ IDEA now to make sure you never lose a single line of code!
Subscribe to Blog updates
Thanks, we've got you!
Profile on the Fly With the IntelliJ Profiler
At JetBrains, we believe that profiling should be simple and accessible to all developers, regardless of their level of expertise. That’s why the IntelliJ Profiler puts ease of use and seamless integration at the forefront of its mission. In previous releases, we introduced a range of features to s…
History of Gradle Delegation Process in IntelliJ IDEA
Nowadays, a build tool is an essential part of any project, and IntelliJ IDEA integrates with the majority of them. Among the most popular build tools is Gradle. We’d like to give a brief historical overview of its integration with IntelliJ IDEA and the delegation process implemented inside the I…
How to Work With Protobuf-Maven Projects in IntelliJ IDEA
Protobuf, short for Protocol Buffers, is a language-agnostic data serialization format developed by Google. It is designed to efficiently and reliably serialize structured data to communicate between different systems and programming languages. Protobuf offers a compact binary representation of data…
Turbocharge Lombok annotations with IntelliJ IDEA
If you’re a professional Java developer, you probably use IntelliJ IDEA as your IDE and Lombok as the framework that handles the Java boilerplate. What you probably didn’t know is that not only do these 2 technologies work well on their own, but when combined, they’re even more efficient than when u…