How to find the commit that broke something after a merge in git?

Written on by Mandeep Singh in Accidents Recovery

Tracking down the commit that introduced a bug after a big merge can be quite time consuming. Luckily git offers a great binary search facility in the form of git-bisect. First you have to perform the initial setup:

 git bisect start         # starts the bisecting session
 git bisect bad           # marks the current revision as bad
 git bisect good revision # marks the last known good revision

After this git will automatically checkout a revision halfway between the known “good” and “bad” versions. You can now run your specs again and mark the commit as “good” or “bad” accordingly.

git bisect good # or git bisec bad

This process continues until you get to the commit that introduced the bug.

Sign up below to receive updates, tips and more handy tutorials when git screws up. It’s good stuff & I don’t spam.