git-bisect - Linux
Overview
git-bisect assists in identifying the first potentially buggy commit in a Git repository. It’s particularly useful for tracking down the root of a regression or bug.
Syntax
git bisect [<options>] start <bad> <good>
Parameters
- start: The starting point of the search (defaults to current branch tip)
- bad: The commit known to be buggy
- good: The commit known to be correct
Options/Flags
- –no-checkout: Don’t check out commits during bisection
- –guess: Make an initial guess on the first bad commit
- –skip: Skip checking specific commits
- –skip-merge: Skip checking merge commits
- –debug: Print additional debugging information
- –all: Bisect all commits instead of just the interval
Examples
Basic usage:
git bisect start v1.0 v1.1
With options:
git bisect --no-checkout --skip merge-commit start v0.9 v1.0
Troubleshooting:
Issue: Bisect gets stuck on a merge commit
Solution: Use --skip-merge
option or manually bisect the merge commit.
Integration
With git-log:
git log --follow --format=" %h" | git bisect skip ^
With scripts:
#!/bin/sh
git bisect start master release-1.0
while git bisect run ./test-script; do
git bisect good
done
Related Commands
- git-blame: Traces the origin of each line of code
- git-tag: Marks commits with descriptive names for easier tracking
- git bisect documentation