Recovering Deleted Code with IntelliJ IDEA Local History
Learn how IntelliJ IDEA’s Local History feature lets you restore deleted files or specific code changes without relying on external version control.
03 Aug 2026, 14:30 UTC

Quick answer: use Local History to undo deletions
If you accidentally delete a file or a block of code in IntelliJ IDEA, you can often recover it without creating a Git commit. The IDE’s Local History feature automatically saves snapshots of your files as you work, letting you browse past states and restore exactly what you need.
How Local History works
IntelliJ IDEA monitors file system events (saves, builds, VCS operations) and creates a snapshot of each file when a change is detected. These snapshots are stored in the IDE’s system directory, not inside your project’s .idea folder. By default, snapshots are kept for five days, after which the oldest entries are purged to limit disk usage.
You can view the history for a single file, a folder, or the whole project:
- Right‑click the file or folder in the Project view.
- Select Local History → Show History.
- A diff window appears, listing timestamps on the left and a side‑by‑side comparison on the right.
- Select a previous state and click Revert to restore that version, or copy‑paste the needed code.
Worked example: recovering a deleted line
Suppose you have a Java class Calculator.java and you accidentally delete a method.
// Calculator.java before deletion
public class Calculator {
public int add(int a, int b) {
return a + b;
}
// <-- this line is about to be removed
public int multiply(int a, int b) {
return a * b;
}
}
After deleting the multiply method, follow these steps:
- Right‑click
Calculator.javain the Project tree. - Choose Local History → Show History.
- In the History pane, locate the entry just before the deletion (the timestamp will match the time you last saved the file).
- The right‑hand side shows the file as it existed at that point, with the
multiplymethod present. - Click the Revert button (or press
Ctrl+Shift+Alt+Z) to restore the file to that state.
The IDE will replace the current file with the selected snapshot, effectively undoing the deletion while leaving any later changes you made intact.
Adjusting the retention period
If you need Local History to keep snapshots longer (e.g., for a long‑running experiment), you can change the number of days the IDE retains data.
- Open the Registry: Help → Find Action → type “Registry” and press Enter.
- Search for
localHistory.daysToKeep. - Double‑click the value and enter a new number (e.g.,
30for thirty days). - Click Close; the change takes effect immediately.
Alternatively, you can add the property to a custom idea.properties file via Help → Edit Custom Properties.
Limits and considerations
- Not a backup substitute: Snapshots are stored locally and are removed after the retention period. Do not rely on Local History for long‑term archival or disaster recovery.
- Machine‑specific: The history lives in the IDE’s system directory on the workstation where you made the changes. It does not sync across machines or with teammates.
- Disk usage: In projects with very high churn (e.g., generated code, large binary files), the Local History folder can grow quickly. Monitor the size of
~/Library/Caches/JetBrains/<product><version>/localHistory(macOS/Linux) or%LOCALAPPDATA%\JetBrains\<product><version>\localHistory(Windows). - No granularity for binary files: While text files are diff‑friendly, snapshots of large binaries (e.g., images, compiled JARs) consume space without providing useful diff views.
Common mistakes to avoid
- Assuming Local History works like Git: it does not track branches, merges, or remote repositories.
- Relying on it after a system reinstall or IDE upgrade: the system directory may be cleared, erasing history.
- Ignoring the retention setting and being surprised when older snapshots disappear.
- Trying to recover a file that was deleted from the filesystem outside the IDE (e.g., via command line
rm) before the IDE had a chance to snapshot it; in that case, Local History will have no record.
Practical verification
To confirm that Local History is active and retaining snapshots:
- Create a temporary file
test.txtin your project. - Make three successive edits, saving after each.
- Right‑click the file → Local History → Show History.
- You should see at least three entries labeled with timestamps.
- Delete a line, save, then use History to revert that line and verify the file returns to its prior content.
If the History pane shows no entries, ensure that the localHistory.enabled registry flag is set to true (the default).
Local History is a handy safety net for everyday coding slips. By understanding how snapshots are created, where they are stored, and how to configure retention, you can use it effectively while avoiding the pitfalls of treating it as a permanent backup.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.