11

Finding a Broken Commit: Bisect and Blame

Sooner or later, you are likely to find that you have a bug in your program that was introduced sometime in the past. You can go searching through all your prior commits, but that is time consuming and inefficient. Git provides a command, bisect, to take care of all the hard work for you.

Here's how it works: bisect asks you for a known "bad" commit. Most often this is the last commit. It then asks for a known "good" commit – that is, a commit that is known to work. You do not have to try out a variety of commits to find this; just far back enough that you can be sure it was working back then.

If you are cautious, you may want to check out the good commit and run it just to make sure.

Bisect will ...

Get Git for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.