Why version control is a life saver…
It was late, and I’d done a long day up to that point. And I was mucking about with some inconsequential code. In fact, I was trying to delete the directory, as I’d finished what I was doing with it.
So I executed that fateful command: rm –rf parserdemo/ *
Now I’m sure almost all my regular readers will know straight away where I went wrong. I didn’t immediately. I was tired, and aching to get home, but after two minutes I thought, “that directory wasn’t that big!!” so I control-c’d it and did an ls.
It wasn’t a pretty sight. Almost every project I’d worked on had gone from my dev directory. Even more worrying was the work I was working on that morning had gone. Now I usually commit my code at the end of the day, (when I remember) so I cd’d in to the the project’s directory, looked ok, maybe I cancelled it in time, but no! I did a git status and got a nasty error message.
Fortunately for me, I actually committed the work earlier that day as I’d finished the ticket I was working on. So fortunately I could blat the directory, re-clone the project and check out against the appropriate branch and sure enough there was the code I’d lovingly written that morning.
The moral of this lesson?
Well first of all, be VERY CAREFUL using rm –rf, because it will just chomp through anything and everything if you’re not careful.
Secondly, if you don’t use version control, then do so. It’s there for a VERY GOOD REASON. And these days you can have your code hosted for free on github or bitbucket or any number of free source code repository sites.
Thirdly, commit your changes often. Because you never know when you need to roll back to something you did by mistake. With git this is very easy, I don’t have experience of other version control systems. I do recall using one tool that you had to check out individual files, then check them back in again against a central repository, you didn’t have the code on your hard disk the way you do with git. But I digress.
The fact of the matter is, I was tired and a wee bit irritable by that point of the day, and I hadn’t realised what I’d done until I looked at the command more carefully. But it’s the kind of mistake you’ll only make once. Hopefully…