LinuxCommandLibrary

git-bisect

Find the commit introducing a regression

TLDR

Start a bisect session on a commit range bounded by a known buggy commit, and a known clean (typically older) one

$ git bisect start [bad_commit] [good_commit]
copy

For each commit that git bisect selects, mark it as "bad" or "good" after testing it for the issue
$ git bisect [good|bad]
copy

End the bisect session and return to the previous branch
$ git bisect reset
copy

Skip a commit during a bisect (e.g. one that fails the tests due to a different issue)
$ git bisect skip
copy

Start a bisect session considering only commits that modify a specific file or directory
$ git bisect start [bad_commit] [good_commit] -- [path/to/file_or_directory]
copy

Automate the bisect process using a test script that exits with 0 for "good" and non-zero for "bad"
$ git bisect run [path/to/test_script] [optional_script_arguments]
copy

Display a log of what has been done so far
$ git bisect log
copy

Show remaining candidate commits to be checked
$ git bisect visualize
copy

SYNOPSIS

git bisect <subcommand> [options] [revisions]

PARAMETERS

start [bad [good...]]
    Begin bisect session; mark initial bad/good commits

bad [rev]
    Mark revision(s) as bad (buggy)

good [rev...]
    Mark revision(s) as good (working)

skip [rev...]
    Skip untestable revision(s)

next
    Checkout next commit to test

reset [commit]
    End bisect and checkout specified commit

run cmd
    Automate with command; continues until resolution

visualize
    View bisect via git log or gitk

replay file
    Replay bisect commands from log file

log
    Output bisect log to stdout

--no-checkout
    Do not checkout commits; use with run

-q, --quiet
    Silence bisect messages

DESCRIPTION

Git bisect performs a binary search on the Git commit history to identify the commit that introduced a bug. Start by marking a known bad commit (with the bug) and one or more good commits (without the bug). Git then checks out the midpoint commit automatically. Test the code at this commit: if buggy, mark it bad; if not, mark it good. Repeat to narrow down the range until the exact commit is found. Subcommands like skip handle untestable commits, run automates testing via a script, and reset ends the session.

It's efficient, typically requiring only log2(N) tests for N commits, making it ideal for large histories. Works on branches and merges. Visualize progress with git bisect visualize or git log. Essential for debugging regressions.

CAVEATS

Requires manual or scripted testing per checkout; clean working tree advised before start; cannot bisect across unreachable commits; run exits non-zero on bad/skip.

BASIC WORKFLOW

git bisect start
git bisect bad HEAD
git bisect good v1.0
Test, then git bisect bad or good repeatedly.
git bisect reset to finish.

AUTOMATION TIP

Use git bisect run test-script where script returns 0 for good, non-zero for bad.

HISTORY

Introduced by Linus Torvalds in Git 1.0.13 (February 2006) to efficiently debug kernel regressions via binary search, inspired by similar tools in other VCS. Evolved with automation (run in 1.5.0, 2007) and UI integrations.

SEE ALSO

Copied to clipboard