git and regression

Posted by March 7, 2011 technick No Comments

Quite sometime ago, I used subversion as the main version control system in my projects. I quite liked it and never wanted to move to git for the main reason being so many repositories and not one single repository to maintain the code and blah blah blah..

Recently, like 6 months ago, I started using git and I am gradually falling in love with it.  🙂

Something that I feel is worth sharing about git is its ability to find regressions. “git bisect”

(master) $ git bisect start
(master|BISECTING) $ git bisect bad
#the current version is bad
(master|BISECTING) $ git bisect good a37b6f0dcc8
#the hash a37b… was good where the tests passed!

This takes you to a hash between the HEAD and a37b… just run the tests here and if they are good, you need to run:
(master|BISECTING) $ git bisect good
otherwise,
(master|BISECTING) $ git bisect bad

This defines good and bad limits of the commits.

Everytime you run the git bisect command, git intelligently takes you to one commit/hash between the good and the bad limits and in a few more runs of the tests, it will finally point you to the actual git commit which caused the regression!

Once you are done, never forget to run:
(master|BISECTING) $ git bisect reset

Happy gitting everyone!