How to conduct a git bisect
Hello and welcome back to my blog! Today we are going to be discussing how to do a git bisect.
What is a git bisect?
A git bisect is nothing but an operation that uses binary search techniques in order to find a commit (among a large set of commits) that potentially introduced a bug in your code.
How to successfully use git bisect
In order to do a git bisect successfully, you will need the following:
- The commit hash / tag as a start point where we know that the bug is present.
- The commit hash / tag where we know that the bug was NOT present.
Follow these steps to start a bisect.
- Issue the following command to start a git bisect on the branch you are on:
git bisect start
- Issue the follwing command to specify the bad commit (by default if no commit is specified, the head of the branch is the starting point.):
git bisect bad [optional: commit_hash]
- Issue the following command to specify the commit hash or tag where you know that the bug was not present:
git bisect good [tag/commit_hash]
Once this is done, git will checkout a a commit version that you can then test to see if it is buggy or no. If not, type in git bisect good
, if it is buggy, type in git bisect bad
.
Repeat this process until you have no more revisions to test. Git will print out a description of the first bad commit. The reference refs/bisect/bad
will point to the first bad commit.
A great example of this is shown in gits own documentation: https://git-scm.com/docs/git-bisect which is the source for this blog.
Hope you learned something new! ☺️