Well, not really, but it’s a very catchy title isn’t it? Anyway, source control has saved my bacon a few times, and although this particular instance wasn’t that dire; it did remind me how important and ingrained into my daily routine source control is now. And because of that; I haven’t lost a single line of code in well over 2 years. That’s not to say there are lines of code I wouldn’t mind loosing, but that’s a different story.
Today, as I was reading comments on this blog, I tried to open the Unity project that I have been using as part of the Unity series on 2D animations. And Unity crashed. So I tried it again, and Unity crashed again. I started to think I was going to have to follow my own blog posts to recreate the project when I remembered that I had done something mind-blowingly brilliant.
When I started the series, I instantly added the Unity project to a Mercurial Repository. Now my main reason for doing this at the time was to make it easier for my faithful readers to get access to the source code for the blog posts. What I didn’t expect at the time was I was going to need it in order to recover a working copy of the Unity Project.
So I fired up my favorite Hg (Mercurial) client, SourceTree, and set to work on the repo. I quickly discovered why the project was failing to open. I had branched from my develop in order to work on a different blog post, and then had played around with some other scripting libraries in Unity.
Realizing what I had done, I was in dismay because now I had two lines of development mixed into a single large mess of changes, Someone had stuck peanut butter in my chocolate! And it was me. Now SourceTree is awesome, I can’t say that enough. I scrolled through the large list of changes that SourceTree had discovered. I selected all the changes that were supposed to be in this branch and committed them. Now what was I to do? I still had over a hundred files sitting in the working copy that didn’t belong there. Trying to switch back to the develop branch fails because I have uncommitted changes. Arrrgh!
No worries, these were the changes I didn’t want anyway, as they were breaking my Unity project to begin with. I fired up the Discard tool in SourceTree, told it to discard all, and voila! all those unwanted changes disappeared, I could now change back to the develop branch. And I can open the Unity project. Disaster avoided.
Wrapping it up
So in the end, what was this all about. It’s about the importance that you need to place on solid practices that can lead to better productivity. One of these practices is by using a source control product, I don’t care which, as part of your daily routine.