Casthoughts

Software and such

May 09, 2022

Why I am fanatical about version control

A short horror story that could have been prevented by git.

So, there I was. The year was 2007 and I was in the process of wrapping up the research I had done as an undergraduate. One of my tasks before heading off to grad school was to archive all of the code I had written over the last two or so years to DVD-R for the lab archive.

My editor writes temporary backup copies while editing to the filename with a ~ appended. Thus, for every source file foo.m I had been working on there was a paired foo.m~ in the directory. At the time I was working in MATLAB and as was the convention had all off my source in one directory. This was the code that I used to generate the figures in my senior thesis and – more critically – the figures of a paper we had in preparation which would require further revision. Not wanting to archive transitory and duplicate files I happily typed

cd all/of/my-source
rm * ~

which very efficiently deleted all of the code I had written over the last two years (“Computers: making mistakes faster than you possibly imagined!”).

I did want any reasonable person would do and spent the next five minutes lying on the floor trying to stave off a panic attack.

In this particular case I was got stupendously lucky. I had every file open in an editor and was able to go through and systematically add a space and re-save all of them. From then on, everything I have written that looks like text that I suspect I may want to keep is very quickly committed into a version control system and distributed to at least two computers.