Deleted a week of code? PhpStorm's Local History got it back
I once deleted a whole week of work by accident. Not a quick prototype: code I had written slowly and carefully. For a few minutes I just stared at the screen.
Then I got up, drank a glass of water, and came back to think instead of clicking. Panicking is how people make it worse: running the wrong command, overwriting files, restoring an older copy on top of what's left. And I remembered that PhpStorm keeps its own history of every change, separate from Git. It got everything back.
What Local History is
PhpStorm, like every JetBrains IDE (IntelliJ IDEA, PyCharm, WebStorm and the rest), quietly records changes to your project files as you work: edits, refactorings and deletions. It has nothing to do with Git. It works in projects with no version control at all, and it includes changes you never committed.
How to get deleted code back
A file you changed: right-click the file → Local History → Show History. Pick a point in time on the left, compare it with the current version, and revert the whole file or just the parts you need.
A file or folder you deleted: you can't right-click something that's gone, so right-click the folder it was in (or the project root) → Local History → Show History. The deletion appears as an entry; select the version before it and choose Revert. The files come back.
The same menu is under VCS / Git → Local History in the main menu, depending on your version.
Before you rely on it
- It doesn't keep everything forever. By default it holds a few days of changes (configurable in the IDE settings), so recover sooner rather than later.
- It's tied to that IDE on that machine. A new laptop, a reinstall, or clearing the IDE's caches with local history included, and it's gone.
- Changes made outside the IDE (a script, a terminal command) are usually recorded when PhpStorm notices them, but only if it was running and watching the project.
So it's an excellent safety net, not a backup.
What I do differently now
- Commit small and often, even if the work isn't finished. A WIP commit on a branch costs nothing.
- Push to a remote at the end of the day, so the code isn't living on one disk.
- Use Local History's labels (right-click → Local History → Put Label) before a risky refactor, so there's an obvious point to come back to.
And if it happens anyway: stop, breathe, and don't touch anything until you know what actually happened. Most "it's all gone" moments aren't, as long as you don't make them worse.
I write about the hard parts of backend work on this site. If you're dealing with something stuck, here's how I can help.