Using Bisect Mode
Starting the Bisect Process
Initiating Bisect
To begin the bisect process, use the following command:
git bisect start
Marking Commits
You'll need to mark known good and bad commits:
## Mark the current commit as bad
git bisect bad
## Mark a specific commit as good
git bisect good <commit-hash>
## Alternatively, mark a specific commit range as good
git bisect good HEAD~10
Bisect Workflow
graph TD
A[Start Bisect] --> B[Mark Bad Commit]
B --> C[Mark Good Commit]
C --> D[Git Selects Test Commit]
D --> E{Test Passes?}
E -->|Yes| F[Mark Good]
E -->|No| G[Mark Bad]
F --> H[Continue Bisect]
G --> H
Bisect Commands
Command |
Description |
git bisect start |
Begin the bisect process |
git bisect good |
Mark a commit as working correctly |
git bisect bad |
Mark a commit as containing the bug |
git bisect reset |
Exit bisect mode |
Automated Testing
You can automate the bisect process with a test script:
## Create a test script
#!/bin/bash
./run_tests.sh
## Use the script in bisect
git bisect start
git bisect bad
git bisect good <commit-hash>
git bisect run ./test_script.sh
Advanced Bisect Techniques
Skipping Commits
Sometimes you might encounter commits that can't be tested:
## Skip a problematic commit
git bisect skip
Visualizing Bisect Progress
Use log commands to track your bisect journey:
## Show bisect log
git bisect log
## Show bisect status
git bisect view
Practical Example
A typical bisect session on Ubuntu 22.04 might look like:
## Start project
cd /path/to/project
## Initiate bisect
git bisect start
## Mark current state as bad
git bisect bad
## Mark an older commit as good
git bisect good v1.0
## Git will checkout intermediate commits
## Test each commit
## Provide feedback (good/bad)
LabEx Pro Tip
At LabEx, we recommend using automated test scripts to make the bisect process more efficient and precise. Consistent testing helps quickly identify problematic commits.