git bisect saved the day

I had a weird bug UI bug. I couldn’t fix it, I couldn’t get around it… everything I did seemed to make the bug worse.

So I spend some time looking at funny pictures of cats, and that’s when I remembered that I had all the power of git to help me… and I heard the cat whispering: “Git bisect to save the day!”

A Funny Cat

Funny cat? You can't be serious...

Yeah, looking at cat pictures makes me go crazy. Go figure…

Coming back to git, I read the doc and bit and away I went:

git bisect start
git bisect good last_good_release
git bisect bad master

git now sent me to a revision between those two… last_good_release can pretty much any commit identifier (a tag, the sha1 identifier…)

I compiled, ran my test… all good. The bug wasn’t in this version.

git bisect good

Git selected another commit. Compile, test… hmmm… the bug appears it this version

git bisect bad

Git bisect helps you do a binary search over your commits. It checks out something in the middle between ‘good’ and ‘bad’. You check to see if the bug is there. If it is, ‘git bisect bad’, if not ‘git bisect good’. And you continue until you find the guilty commit.

Eventually I found the culprit… It was nowhere near where I thought the problem appeared to be. I had lost a lot of time… but I found it, thanks to git!

Git bisect saved my day.

2 Responses to “git bisect saved the day”

  1. David Gageot says:

    Your post echoes my post a few weeks ago, “Git might save your day”: http://blog.javabien.net/2010/03/23/git-bisect-might-save-your-day/

    Strange title familiarity.

  2. Lesson of the day : I should google my blog title before I post…

    It’s good to see I’m not the only one getting saved by git :)

    I really like the way to automated the process using ‘git run’ in your blog post. I’ll add that to my bag of tricks.

Leave a Reply