← Writing Code Snippets From the archive

Git Bisect and Why it is Amazing

Git bisect is a really helpful, someone under-appreciated tool in Git.

Words
Justin Sainton
Published
Reading time
1 minute

Had a client email me recently, mildly concerned, as an update to WP eCommerce broken his search layout. I told him that I couldn’t think of anything between the latest version and the prior version that would have caused any such thing, but I’d be more than happy to check it out.

Initially, if I’m being quite honest, I just assumed it was user error.  It’s easy to mis-configure things, set up a theme wrong, etc. Any number of things can go wrong. But, I dug in and in fact, we had broken it.  I didn’t recall any changes in the 913 commits between the two changes.

With nothing obvious, and 913 commits between release – what was a developer to do?  Enter, git bisect.

Git bisect is amazing. Prior to using it, you might think to yourself,

“Hmm, self, I suppose I can checkout a few different commits, figure out a commit where it works, and one where it doesn’t, and sort of narrow down a range until I find it.”

And that would be a really good thought.  But it would take you, a human, waaaaaaay longer than git would take.  That very thought you had? That’s what git bisect does.  Imagine you have the master branch, latest commit checked out.  You know that a previous version branch worked fine.  Check this out.

git bisect start
git bisect good
git bisect bad branch-3.8.14.4

And boom, you’ve started down the path. Git will analyze how many revisions exist between good and bad, split the difference, and checkout that commit. Then, test to see if the bug still exists. If it does, git bisect bad. If not, git bisect good. It will keep narrowing down the commits until it finds the precise commit that caused the issue.

In case you remain unconvinced – remember – I was able to wade through 913 commits to find the single commit that caused a bug in a piece of software that spans hundreds of files and over 150,000 lines of code.

It took about three minutes.

Git bisect is amazing.

Next up · December 10, 2014 · 2 min

How To: Remove Shipping Calculator from WP eCommerce

Keep reading →

More to read

All writing