originally posted at http://www.goodfeelingplace.com/source-control-feels-good
Today I want to sing praises for source control. I was working on an inventory application this morning, putting a few final touches on the display of the data to make it more crisp and clean looking. In this application I used the extjs grid view library (see www.extjs.com for more info) to display the data so the columns could be resized dynamically and it would look and act more like excel than a web page. Unfortunately something I did this morning caused the column headers to get left justified and lose connection with the centered data, and I lost the scroll bars even though the data was bigger than the box (div) containing it.
After digging myself in a hole and getting angry and frustrated, my wise wife Candice convinced me to take a break and have lunch. After she helped me move up the emotional scale a bit (and I had a good lunch), I was able to figure out why everything went crazy – it was because I took out my carefully calculated container sizing code and set the width and height to “auto”. But at the time I was so excited to find a way to make the size exactly match the contents that I had deleted my calculations (eight different calculations, 2 for each of 4 different data grids). This is where source control came to my rescue. I use bazaar (see http://bazaar-vcs.org/) to save changes to my code, so once I figured out (based on my log entries) which revision I had deleted the code that I needed, I typed this simple command to create a text file with the code that I had deleted from 3 different files:
>bzr diff -r156..157>heights.txt
(bzr diff shows the differences between versions, -r156..157 specifies the two versions I want to see the differences in, and >heights.txt causes a text file called heights.txt to be created in the current directory with the results of the request)
Then I just opened up the created text file and copied over the code that I wanted to put back in my current files, and created a new version with a command like this:
bzr commit -m “restored column header centering and scrollbars by setting the div height and width explicitly using calculations based on the number of records to display”
This whole procedure took a few minutes and felt great, because it saved me an hour of recreating the code while kicking myself for deleting it. I love source control 🙂