This blog discusses how we can use git bisect command to find commit that has introduced bug recently.
Git command that uses binary search to find the commit that introduced a bug.
I will take very easy example of a button that is supposed to navigate user to /blog
path.
But in recent commits this is broken.
Lets find out the commit which broke it.
Here is the recent commit history
$ git bisect start
$ git bisect bad
/* I have not provided any bad commit,
So git will consider latest as bad commit
*/
$ git bisect good db32414
Git bisect will pick a commit between those two endpoints and ask you whether the selected commit is "good" or "bad". Test if the bug is present or not and update same with git bisect bad
or git bisect good
command.
Keep following step 2. Git bisect will continue narrowing down the range until it finds the exact commit that introduced the change.
$ git show commitID
I can see this commit has changed the to
path to incorrect value.
$ git bisect reset
$ git bisect skip
If you use git bisect, you can save a lot of time (that you will spend into debugging). and narrow down the code you need to check to resolve bug.