Git Bisect; Find The Needle In The Haystack
The 3 W's of git bisect:
What: Git bisect is a powerful tool that can help you find the commit that introduced a bug into your codebase. It works using binary search - dividing the commit history into two halves and checking if the bug is present in either half. If it is, it narrows down the search to the other half and repeats the process until it finds the exact commit that introduced the bug.
Why: Finding the commit that introduced a bug can be a time-consuming, frustrating, and exhausting process, especially if the codebase has many commits. Git bisect helps automate this process, saving you time and effort.
How: To use git bisect, first you need to identify a commit where the code was known to be working correctly (the "stable" commit) and a commit where the bug is present (the "broken" commit). Then you can run the git bisect command and specify the good and bad commits. Git will then repetitively checkout to the middle point in the commit history between the “stable” and the “broken”, narrowing down the search until we find the exact commit that introduced the bug. Note – git bisect doesn’t perform the build / test / deployment automatically, you will need to do it. Git bisect helps finding the first commit introducing a bug in the most effective way.
领英推荐
Git bisect can be thought of as a tool for finding a needle in a haystack, where the needle represents the commit that introduced a bug, and the haystack represents the entire commit history of a codebase. Just like how it can be difficult and time-consuming to manually search through a haystack to find a needle, it can be challenging to manually search through a codebase with many commits to find the one that introduced a bug.
Using binary search, git bisect can help you quickly and effectively find the commit that introduced a bug in the code, much like how a needle in a haystack can be found more quickly with the use of a tool like a magnet or a metal detector.
One additional thing to consider is that git bisect is not just limited to finding bugs in code. It can also be used to find any change or commit in a repository that introduced a specific change or behavior. For example, you could use git bisect to find the commit that introduced a change in the design of a website or the commit that introduced a new feature in an application.
Overall, git bisect is a powerful tool to have in your toolkit, as it can help quickly and effectively find the root cause of a problem or change in the codebase.
Front-End Wizard
2 个月git bisect at medium https://www.dhirubhai.net/posts/vitalii-semianchuk-9812a786_git-debugging-softwaredevelopment-activity-7269071149827821570-njpA?utm_source=share&utm_medium=member_desktop
Backend Developer
2 年Well written as always! Waiting for your next article ??
Group Leader at Varonis | Speaker | Author of The Tightly Coupled blog | Azure Solutions Architect Expert | Azure AI & ML Certified
2 年????!?
DevOps-CI Engineer at Varonis | 8200 Alumni
2 年Very useful!