git bisect, we can find the bad commit much easier. git bisect is a git command used to find the commit that introduced a bug in your code. We mention a good commit where there was no bug and also a bad commit where we noticed the bug. git bisect picks a commit in between and asks if the commit is good or bad. This goes on till we find the bad commit. git bisect works just as a binary search does. To get started with git bisect, we run the command
git bisect startNow, we add the good commit. The syntax is
git bisect good commit_idThen, we add the bad commit as the following syntax.
git bisect bad commit_idNow, the command will trigger splitting the commits into half and revise it. We respond if the commit is good or bad as git bisect good or git bisect bad. The revision is narrowed down until we find the commit that caused the bug. Sometimes, we can automate finding the bugs. We can pass any script and check the script against each commits. The commit returning a non-zero status is the failing one. Here, as an example, I am running a failing test
git bisect run rspec spec/features/my_broken_spec.rbgit bisect is an awesome method to find the commit which caused the bug. It helps us saving our time and money. ]]>