A Mysterious Bug

A Mysterious Bug

Imagine you're working on an application that has been running smoothly for months. Suddenly, a colleague reports that one specific functionality is broken. Panic sets in as you realize the application has undergone numerous changes over the past few weeks. Manually checking each commit would be a nightmare. This is where Git Bisect shines.

Step 1: Start the Bisect

First, identify a "good" commit where the feature was still working and a "bad" commit where the bug is present. Let's say the last known good commit was two weeks ago, and the current commit is bad. You start the bisect process with:

git bisect start
git bisect good [good_commit_hash] 
git bisect bad [bad_commit_hash] # typically the HEAD        

Step 2: The Binary Search Begins


Git Bisect now checks out the middle commit between the good and bad commits. You test the functionality on this commit. If it's working, you mark it as good:

git bisect good        

If it's broken, you mark it as bad:

git bisect bad        

Step 3: Narrowing Down the Culprit

Git Bisect continues this binary search process, checking out the middle commit of the remaining range each time. With each step, the range of potential problematic commits narrows, bringing you closer to the source of the bug.


Step 4: Automating the Process with git bisect run

To make the process even more efficient, you can automate the testing using a script. Suppose you have a script named `test_bug.sh` that returns an exit status of 0 if the specific feature works and 1 if it doesn't. However, this specific test is always tricky and should not be contaminated with any side effects. You can automate the bisect process with:

git bisect run /full_path_of_test_script/test_bug.sh        

Git will automatically run the script at each step, marking commits as good or bad based on the script's exit status. This automation saves time and effort, especially in large codebases.

Step 5: The Revelation

Finally, after a few iterations, Git Bisect isolates the commit responsible for the bug. You discover that a recent change inadvertently introduced a regression. With this knowledge, you can quickly address the issue and restore the functionality.

Step 6: End the Bisect

Once the problematic commit is identified, you end the bisect session:

git bisect reset        

This returns you to your original branch state, ready to implement the fix.


Git Bisect is an invaluable tool for efficiently tracking down bugs, saving developers time and effort.

要查看或添加评论,请登录

Deepak Rout的更多文章

  • Do You Know What the RELY Option in a Primary Key Does on Databricks?

    Do You Know What the RELY Option in a Primary Key Does on Databricks?

    If you're working with Databricks SQL and want to supercharge your query performance, it's time to explore the RELY…

  • Be Careful with NULL Handling During Database Migrations

    Be Careful with NULL Handling During Database Migrations

    When migrating databases, especially when using window functions like ROW_NUMBER(), RANK(), or DENSE_RANK(), one subtle…

    1 条评论
  • YAML Engineers

    YAML Engineers

    In the data engineering field, YAML files have become a beloved tool, much like in DevOps. Over the years, data…

  • Lost in translation

    Lost in translation

    I was scrolling through my LinkedIn feed the other day when I stumbled upon this hilarious (and kinda sad) interaction.…

  • The Modern Alternative to Makefiles

    The Modern Alternative to Makefiles

    Have you ever stared at a Makefile, feeling lost in a sea of colons, tabs, and cryptic syntax? You're not alone. Many…

  • Where Is Everyone ?

    Where Is Everyone ?

    Ever sent out a status update, shared code for review, or posted in a team channel only to be met with..

    1 条评论
  • SQL Productivity Hack

    SQL Productivity Hack

    As a data consultant, I often find myself writing SQL queries to move data between tables with some transformations…

    1 条评论
  • "ASOF JOIN: Bridging the Time Gap in Data Analysis"

    "ASOF JOIN: Bridging the Time Gap in Data Analysis"

    You must have been hearing more and more about a new type of JOIN called . Modern databases are adding this feature to…

  • Value-Focused Framework

    Value-Focused Framework

    As leaders in the digital age, we must look beyond technology and patterns to embrace a holistic view of architecture…

  • MAX_BY Magic

    MAX_BY Magic

    MAX_BY, a powerful yet under utilized SQL function, is a game changer for writing readable and intuitive SQL. returns…

    2 条评论

社区洞察

其他会员也浏览了