In this article, we will discuss about how to use, when to use the git bisect.
What is git bisect?
Git bisect is a command line tool that helps us to find the commit introduced a bug or regression in the repository.
It uses binary search to find the commit that has a bug. Using the git bisect, we can divide the entire commit history into two halves and perform a binary search on each half until the commit which caused the issue is found.
When to use git bisect?
When we have a project with a large commit history and notice that a feature that used to work perfectly is now broken.
We have no idea which commit caused the problem. In such a case, manually tracking down the commit that caused the problem is difficult. This search can be improved using the git bisect.
How to use git bisect?
1. Start the git bisect process
Entire the following command to start the git bisect process
git bisect start
2. Identify a good and bad commit
Now, we need to provide the good commit & bad commit information to the git bisect. Good commit is the point where no bug is present and the bad commit which contains the bug that we are trying to track down.
git bisect good <commit>
git bisect bad <commit>
3. Testing the commit
After selecting the good and bad commit. Git will provide us a commit to test. After testing the commit, we should tell the git whether that commit has issue or not. If still the issue is present in the commit provided by git then use the following command to tell that it is bad else inform git that it is good.
git bisect good
git bisect bad
After the above process, then git will select another commit for us to test, and repeat the process until Git identifies the exact commit that caused the issue.
4. Abort the git bisect?
Once the git identifies the exact commit that caused the issue, we can end the bisecting process by using the following command.
git bisect reset
This will return us to state it was before we started the git bisecting process.