Tracking origin of bugs with git bisect
I’ve been involved with a iOS project this past week. I’m adding functionalities to the CommonSense iOS library. One of the most annoying thing is that it took about 2 minute to load the project. This is only happened in the unstable branch. The master branch seems to be working fine. So I knew that somewhere there is a commit when this starts happening.
Now this is a good example where git bisect
is very useful. It will perform a binary search through commit history until the first
bad commit found. So you start with a commit and you marked is as a ‘good’ or ‘bad’. Then every time you mark a commit as good / bad,
it will then checkout another commit half way in the middle point between previous history. In each checkout then you test the code and see
whether the bugs exist or not.
Here is an example
|
|
the prompt sense-ios-library
shows the current folder, and git:(unstable)
show current commit. it’s part of oh-my-zsh plugin
|
|
Now that you know when was the bugs introduced. you can now start looking at the problem.
I found out there is something that doesn’t feel right here github:commit/e5c40.
There is a reference to Xcode.app
in one of the folder. So every time I open the project,
or switch branch, it will try to look into things inside Xcode.app
.
So removing the reference indeed solve the problem.
The bisect function is very versatile tool to track down when a bug was introduced. You can even automate the test so you don’t have to check each bisect commit your self. The bisect documentation provide a good explanation about the command and also an example on how to automate the test.
Now go on catch and squash those annoying bug!
comments powered by Disqus