Best of Git

git bisect

If you have an atomically-versioned commit history, you will be happy to know that the most powerful git command is going to save you a lot of time.

Exhibit A: I just realized there is a bug in my program, for some particular edge-case functionality. How do I find when this bug came up, and what code caused it?

First, I could manually step through the history and see when it came up.

Second, I could use git bisect.

git bisect start # Starts the process
git bisect bad # master branch has the bug!
git bisect good v0. # I know this ancient version does not have a bug.

Now, the process starts. You can hit good or bad on each commit that comes up, or automate it(!):

{ make -B && make -B libcs.a && \
    cd .. && make rts_sim && \
    cd ../test/sim-data } || { exit 125 }

exit 0

This is a script I have to go through the build-and-test process automatically. An exit code of 125 will cause bisect to skip the commit (meaning it is due to a different issue than the main bug), so in this case, compiler errors aren’t important.

Then, git bisect will find which commit caused the binary to fail on the test case (here: