Sometimes bisection is the fastest or the only way to find out which commit caused a bug or regression. The git bisect
command makes the bisection process quite easy by managing the binary search process for you.
You start by telling git you want to start bisection:
$ git bisect start
Next you indicate the bisection range, by specifying the good and bad commits that bookend the range. For example, if my current checked out commit is bad and some past commit 1234567
was good:
$ git bisect bad
$ git bisect good 1234567
Git now does bisection on the range and checks out a commit in the middle of the range. You now figure out if this commit is good or bad and indicate that to git. Say the commit in the middle is bad:
$ git bisect bad
Rinse and repeat until the binary search lands on the bad commit that caused the bug.
Once your investigation is complete, reset the bisection to return to a normal git workflow:
$ git bisect reset
Reference: git-bisect