Categories
guides

Git Bisect

tl;dr

# start the session
git bisect start

# mark good/bad
git bisect good abc123
git bisect bad def456

# mark each revision
git bisect good

# end the session
git bisect reset

Some more details…

I love this tool, but always forget how to use it.

Start the bisect session:

git bisect start

The first thing we need to put some “bookends” on the session, or tell git a spot we know in the repo is that is good, and a spot that we know is bad:

git bisect good <term>
git bisect bad <term>

These can be run in either order, and <term> can be any of the following:

  • omitted, and git will assume that you are referring to wherever the HEAD is currently at
  • a commit hash
  • a branch name
### examples ###

# mark current position as bad:
git bisect bad

# mark hash abc123 as good
git bisect good abc123

# mark brach new-feature as good
git bisect good new-feature

After you’ve set the bookends, git will automatically ‘bisect’ the commits between, and jump to one of them. Now test to see if the problem exists, and then mark the current commit as good or bad.

git bisect bad

Keep doing this (test and mark, test and mark, test and mark…), and git will keep moving those “bookends” closer and closer together until it figures out exactly which commit introduced the problem:

a23d6b9cf49779f8980d9cf2f04f5366 is the first bad commit
commit a23d6b9cf49779f8980d9cf2f04f5366
Author: John Doe <john.doe@domain.tld>
Date:   Tue Mar 23 12:13:14 2021 -0700

    My commit message, updates to features and such

 app/file1            | 102 +++---
 app/file2            |   2 +-
 app/folder/file3     | 391 ++++++++++++---------
 tests/file4          |  45 ---
 4 files changed, 271 insertions(+), 269 deletions(-)

Now, you can investigate that commit to see how it broke your stuff.

To exit the bisect session…

git bisect reset

By bo.

I'm @boyEatsSteak in a lot of places. I have been wanting 🍕 for weeks. I like gadgets and technology and keeping notes and tips for my future self since all I can remember is that I forget things.