git checkout -- .
Git can be your friend, when you don’t act wisely, it will unleash its super power against you.
Well… This is a story, that happened to me long time ago, and truth, I started writing this story in 5 years ago and never published it, until now.
I have been working on a massive code base all day, with a full day worth of work in my local repository and wanted to commit all the changes. I admit, I was keep working without making any commits intermittently, as I was zoned out. I mean, literally, I was in the zone.
It is a good feeling when you get in the zone, and just type code like a maniac until you realize you have lot of changes needed to be committed. What do you do when that time comes, ofcourse, your muscle memory will just punch out the keyboard with
git add * and
git commit -m 'message' and that is done, right?
But in my case, I just added all my changes and realized that some part of the change we supposed to be committed separately, which I needed to unstage and later stage it and commit it. So I wanted to unstage few files that need further attention and tried to unstage them, but instead I accidentally issued
git checkout --.
Boom…. My accident turned out to be pretty disastrous mistake, that it wiped out all my work that were uncommitted. Wiped out clean!!!
I was left with nothing but empty slate on my IDE, I was desperate! But, my trusty good JetBrains IDE came to the rescue. I love using collection of JetBrains IDE’s for all my different programming need. It keeps a local history of your code in the background which I used it to retrieve all my codes back in no time. My other solution that I was going to use was, using the
time machine to restore back to the last backup time to retrieve the codes I lost. The latter way, would have been not that perfect, because, I would still had lost couple hours worth of code in the recovery process. My thanks to JetBrains!!!
Nevertheless, when you have power, you have to yield it more cautiously, always make sure that you use Git wisely. Never do
git checkout --. without making sure what you are doing.