TL;DR:
Use View > Recent Changes
and select the most recent “External change” entry to save 97 files you’ve lost due to inherent stupidity.
Today while working on porting my lunchline project to Deno, I made a grave error. I was heavily utilizing Typescript’s path aliases feature to make my imports a bit cleaner. I didn’t feel like messing around with Deno’s import maps (which probably turned out to be a mistake). So I decided I was going to manually rewrite every single import to be relative. (Look I’ve never claimed to be the brightest bulb in the box).
To be fair, at the start of what became an hour-long ordeal, I just wanted to see what the minimum amount of work was required to get deno to run my project. Previously I was using an old version of ts-node and cobbled together a ton of extra various libraries. This project was my first “real” project using Typescript to create a CLI tool, so lots of lessons were learned along the way. One such lesson was that it’s a major PITA to try to run Typescript natively as a node tool (at least at the time).
Now we have beautiful tools like Deno and Bun, which make this all a breeze. But I digress.
At any rate, I was heavily invested in just getting this damn thing to compile and run. After an hour—success! I had a working version of my project running in Deno. This is the moment you sit back and take pride relish the sweet moment of victory.
I hastily moved to my terminal to run git save
to commit my changes.
I typed in gc .
slapped “Enter” and paused… Where were my files?
I ran git status
out of habit and the blood drained from my face as it slowly dawned on me what had happened.
I meant to run my custom git alias git save
which creates a “SAVEPOINT” commit with all my local changes.
I had actually run git checkout .
which is the command to discard all local changes.
I had just deleted the last hour of my work. Literally right as I had GOTTEN IT TO WORK.
A mixture of anger, denial, and sadness washed over me.
However, all was not lost. This is not the first time I’ve accidentally lost my work with a misplaced git command. I knew IntelliJ (and all JetBrains IDEs) have a feature called “Local History” which keeps track of all changes to your files. Importantly, they do this separately from your chosen VCS system.
I went to one of my files, used it and to my relief saw all my changes pop back up.
“Hallelujah!” I thought to myself.
There was only one problem.
I just reset 1 of 97 changed files. I was going to have to manually open up each individual file, navigate to Local History > Show History... > <Select Revision> > and then revert it
.
There’s no way. I’d just go ahead and light this whole project on fire to keep me warm in my depression.
But then—a ray of light came beaming through my LG monitor.
Blasting sweet, sweet wisdom straight from Cédric Champeau’s finger tips into my eye holes.
Cédric had written a blog post about a similarly-doomed situation.
(In hindsight, the situation in his post was actually much worse than mine; his co-worker had lost TWO WHOLE DAYS of coding).
((Ironically, this is the purpose of my git save
command—so that I can frequently commit my work 🙃))
Once found, the solution was so beautifully simple:
- Navigate to “View”
- Select “Recent Changes”
- Find the most recent “External change” entry
- Click it.
And that’s it.
I love Vim. I love my terminal. I love the command line. But this is why I still use a heavy, feature-packed IDE like IntelliJ. I can get all the goodies from my above-mentioned love-affairs; but I also get little-used but life-saving features like local history. (And yeah, I’m sure there’s a vim plugin for this, but I’m hear to sing IntelliJ’s praises because I’m really happy OKAY?)
Thanks for reading! If you enjoyed this, you may also enjoy following me on twitter!