Doers of

A place to Do Stuff and see Stuff Done…

Git ‘er done… well, almost…

I use two laptops for my code training. Well, three actually. I have a Lenovo W520 with 32G of RAM I do most of my coding on. It’s old, a bit beastly and the battery, which was never long lived while new is even less so now. So, even though I have an extra power supply in case I do want to travel with it (so I don’t have to extricate the one from the cable management system under my desk) it rarely travels. I do have another W520 with 16G of RAM, which I’ve moved most of my non-coding things too such as email, music, casual web browsing, etc. My other laptop is a Lenovo Helix with 8G of RAM on it. Not exactly a powerhouse, but it runs what I am currently doing, if a bit slowly. Even though it is also aging quite a bit, its battery still lasts much longer and does a reasonable job when I am caught waiting elsewhere, traveling or what have you.

To keep things in sync, naturally I use Github. Fortunately, most of the tutorials I am working on are fairly short with nice breakpoints, allowing me to commit often. Then, whenever I travel, I push to Github, and often, immediately do a pull on my Helix before I go. Then, no Internet needed. When I get home, reverse the process and wallah! All is well.

Unless of course, I forget about the code on the Helix and work busily away on the W520 for a couple weeks….

Now, I’d like to say, this is the start of a nifty tutorial on how Git saved the day and demonstrate a few short steps to save YOUR day and your sanity. Maybe some other day.

Sadly, this one ended in narrowly avoided disaster. For the most part, I coincidentally had been making separate scripts for each tutorial, so most of the files were not a problem. There were two exceptions to this, and a third, self-inflicted problem.

The first was the one I feared the most. One of the files with conflicts was not actually mine. It was one of the control files for the Unity editor. Specifically, it was the scene file. This file is maintained automagically by the editor and should generally speaking, not be manually edited. If you have used Unity and ever had it ask you to “save” it was, at the very least, writing this file.

Fortunately, it is a text file which gives you a fighting chance to guess and a good visual diff editor can make this much easier. Yes, I’ll take the hit here, for not being more comfortable with the git diff and merge command line display. It really is all there, but let’s face it, I’m just barely young enough that visual diff editors have always been available to me. So, as comfortable with the command line as I am for most things, I draw the line at diff’ing and merging files on the command line.

Not surprisingly, Visual Studio has a built a in visual diff editor! Clicking on the “Open Merge Editor” on the message bar took me right there. With a sigh of relief, I dove in, resolved the conflict and fired up Unity on the Helix and all was well with the world. I continued working away and when I was finished, I committed and pushed and felt good about myself. Git saved the day.

Then I got home…

Again, not surprisingly, when I did a git pull, there were conflicts, including the Unity Scene file. Confidently I waded in and merged the Scene file. There were several other merge conflicts, but they were trivial, mostly being nothing more than formatting cleanup. But I did notice one other problem. I had used the same name for two different scripts. Sadly, because the older one did not include what has since become my standard documentation header, I was not completely sure if the one file was a separate tutorial, or just an earlier version of the current one.

After some investigation I determined both files to have been separate tutorials, which meant I needed to rename one of them. This is where things went awry. Even if I could accurately recreate what I did, I don’t think I would, because it was clearly wrong. Suffice to say, I finally worked it out, thankful these scripts are trivial and took little effort to fix up (note: there was a little extra work because the Unity editor does keep a meta file for each script, but that did not take much to deal with either).

I wish I could say this was the end of the story and sign off with an “All’s well that ends well…” but I can’t. Somehow, I managed to overwrite the Scene file, with the git merge messages embedded in it. No idea how I pulled that one off. The funny thing is, the Unity Editor recognized the file had “uncommitted merge” statements in it, but Git and Visual Studio did not!

Again, eventually, through random acts of guessing, I got it fixed. So…

All’s well, that ends well…!

Leave a Reply

Git ‘er done… well, almost…

by Robert time to read: 3 min