Using git bisect to find where something broke

May 9, 2011 Pivotal Labs

We recently had an issue where our CI build broke over the weekend.

We used git bisect to figure out where the problem occurred.

We wrote a cucumber feature (feature/path/to/is_it_fixed.feature) that worked on Friday and fails today.

We start by setting up git bisect:

git bisect GOOD BAD

Where GOOD is the git SHA from last Friday and BAD is this morning’s SHA.

Then we created a shell script that will setup the environment and run the feature:

#!/bin/bash
set -e

git checkout .
rake db:drop
rake db:create
rake db:migrate
rake db:test:prepare
cucumber feature/path/to/is_it_fixed.feature:20 -r features

We then run this command with the following:

git bisect run /path/to/shell/script.sh

This will then automatically keep running until it finds the SHA that breaks that feature. At the end of the run, it helpfully prints “SHA __ caused the issue”.

Very cool.

About the Author

Biography

Previous
New in Pivotal Tracker: Story tasks now draggable, enabled by default
New in Pivotal Tracker: Story tasks now draggable, enabled by default

We've made a few improvements to how story tasks work in Pivotal Tracker. They're now turned on by default ...

Next
How Cloud Foundry Works When a New Application is Deployed
How Cloud Foundry Works When a New Application is Deployed

Previously in this blog post, we covered how the client side does a vmc push to deploy an application onto ...