Git bisect

Oh how I love git bisect

In the last couple of weeks I had some bugs that were introduced at a unknown commit. Actually I couldn't even find out what code was working wrong.
I did however know excactly what was wrong in the UI.
For problems like this git bisect is perfect.

What git bisect does is it helps you do a binary search in the commits and find the buggy commit.

So you start by finding a good commit.
In order to make the bisect process as fast as possible do not go too far back in history.
How you find this good commit is not reelvant here. But probably you have a tag or someting that is known to work.

So the first thing you do is

git bisect start

This tells git to start the bisect process.

Then when you are at HEAD you mark this as bad (assuming that head is bad)

git bisect bad

Then you mark the good commit you found above as good:

git bisect good abc

Here "abc" is an id of the bad commit probably a sha or tag.

Git will now check out a commit in between the two commits you marked as good and bad. You can now run (or compile) your code and check if it is good or bad.
When you find out, you tell git by issuing a

git bisect good


git bisect bad

Git will then continue checking out commits for you to test until it can tell excactly where the bug was introduced.

When the right commit is found you reset by running

git bisect reset

This tool is very helpful in helping you find code that introduced a bug in the UI.

*image courtesey of *