Introduction
Git bisect is a vital tool for diagnosing the introduction of issues in your codebase. This guide covers how to use git bisect both in Lazygit and through the basic terminal, offering flexibility depending on your preferred workflow.
Lazygit
-
Accessing the Commits View:
- Navigate to the commits view in Lazygit, typically under 4. Commits.
-
Starting Git Bisect:
- Press
b
on a commit to mark it as good or bad, initiating the git bisect process.
- Press
-
Identifying the Problematic Commit:
- Continue marking commits as good or bad based on whether the issue is present. Lazygit automates the checkout process for you.
- Repeat until the commit causing the issue is identified.
Basic Terminal
-
Starting Git Bisect:
- In your terminal, start git bisect:
-
Marking Bad Commit:
- Mark the current HEAD or any known bad commit:
-
Marking Good Commit:
- Mark a commit where the issue was not present:
- Replace
<commit-hash>
with the hash of the known good commit.
-
Narrowing Down the Commit:
- Git will automatically check out a commit for testing. Test the code to see if the issue is present.
- Mark this commit as good or bad accordingly: or
- Git will continue to guide you to different commits based on your input.
-
Ending the Bisect:
- Once the problematic commit is found, end the bisect session:
- This command returns your repository to its pre-bisect state.
Conclusion
Whether using Lazygit for a more graphical approach or sticking to the basic terminal for a more traditional method, git bisect is an incredibly effective way to track down the specific commit that introduced an error or bug in your project.