Bisect

Advanced Git

Amanda Crawford-Adamo

Software and Data Engineer

What is git bisect?

A tool that uses binary search to find the commit that introduced a bug

Git Bisect Command

git bisect

Purpose

  1. Find the bad commit fast
  2. Essential for data debugging
  3. Speeds up root cause analysis
Advanced Git

Bisect - start

  1. Initiate git bisect session

    git bisect start
    
  2. Initialize the current state as a bad state

    git bisect bad
    
  3. Mark the last known good state

    git bisect good <commit-hash>
    

Graph of commits that show the first two commits as good commits denoted by the green color. The last commit is red denoting that this is the known bad commit. In between the good and bad commits, there are three commits where it's unknown if they are good or bad commits, which is denoted by the gray color. The last good commit is marked by git bisect good and the bad commit is marked by git bisect bad.

Advanced Git

Bisect - search

  1. Marks the commit state as a bad commit

    git bisect bad
    
  2. Marks the commit state as a good commit

    git bisect good
    

Graph of commits that show the first two commits as good commits denoted by the green color. The last commit is red denoting that this is the known bad commit. In between the good and bad commits, there are three commits where it's unknown if they are good or bad commits, which is denoted by the gray color. Git bisect uses binary search to start with checking the middle commit. It thens will check the commit to the left or right.

Advanced Git

Bisect - automated search

Checks if the commit version is good or bad by running an automated test script.

git bisect run <script_name>
  • The script must return 0 if the tests passed.
  • If the tests fail, it should return a non-zero number.

Graph of commits that show the first two commits as good commits denoted by the green color. The last commit is red denoting that this is the known bad commit. In between the good and bad commits, there are three commits where it's unknown if they are good or bad commits, which is denoted by the gray color. Git bisect uses binary search to start with checking the middle commit. It thens will check the commit to the left or right.

Advanced Git

Bisect - result

Git Bisect Output Example

$ git log
b1a534f is the first bad commit
commit b1a534f89l2c3d4e5f6g7h8i9j0k1l2m3n4o5p
Author: Jane Doe <[email protected]>
Date:   Thu Mar 14 14:30:00 2024 -0500

Update data transformation logic

Exits the git bisection process and return to our current HEAD

git bisect reset
Advanced Git

When to use git bisect

Use cases

  1. Find regressions in data workflows
  2. Use test scripts for faster debugging

Tips

  • Automate testing with git bisect run <test-script>
  • Use descriptive commit messages to aid the process
Advanced Git

Let's practice!

Advanced Git

Preparing Video For Download...