Lesson 10
Git Bisect
In this lesson, we will explore the concept of Git bisect, a powerful tool that helps you find the commit that introduced a bug in your codebase. We will cover how to run a bisect session, automate bisect with scripts, and understand the benefits of using Git bisect.
Objectives
- Understand the purpose of Git bisect
- Learn how to run a bisect session
- Automate bisect with scripts
- Discover the benefits of using Git bisect
Understanding bisect
Git bisect is a binary search tool that helps you find the commit that introduced a bug in your codebase. By marking commits as "good" or "bad," Git bisect narrows down the range of commits to find the exact commit that caused the issue.
Running a bisect session
To start a bisect session, use the git bisect start
command. Then, mark the known good and bad commits using git bisect good <commit>
and git bisect bad <commit>
. Git bisect will then guide you through the process of testing commits until the culprit commit is found. Once the session is complete, use git bisect reset
to return to your original branch.
Automating bisect with scripts
Git bisect can be automated using scripts to test commits. By providing a script that returns 0 for good commits and non-zero for bad commits, Git bisect can automatically find the commit that introduced the bug. To use a script, run git bisect run <script>
.
Exercises
Manual Git bisect
- Clone the repository 'eriknewland/gitty' and find a commit range with a known bug
- Start a bisect session and manually test commits to find the commit that introduced the bug
- Don't forget to reset the bisect session when you're done.
Automated Git bisect
- Using the same repository and commit range from the previous exercise, create a script that tests for the bug
- Run an automated bisect session with your script to find the commit that introduced the bug
- Remember to reset the bisect session when you're done.