linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Tools/bisect

kb/tools ── Tools ── intermediate

git bisect

Binary search for the commit that introduced a regression. You mark a known-good commit and a known-bad one, and Git finds the exact SHA in log(N) steps. `git bisect run` automates the process with a checker script.

view as markdownaka: git-bisect

Bisect is the most underrated tool in Git. On a history of tens of thousands of commits it pinpoints the source of a regression in 10-15 steps.

Basic manual workflow

bash
git bisect start
git bisect bad                # current commit is broken
git bisect good v1.4          # v1.4 is known to work

Git checks out the midpoint commit. You test it and respond:

bash
git bisect bad     # bug is present
git bisect good    # bug is absent

Git halves the interval and checks out the next candidate. After log2(N) answers:

a1b2c3d is the first bad commit
commit a1b2c3d
Author: ...
Date:   ...
    refactor: extract calculator class

When you are done:

bash
git bisect reset       # return HEAD to the branch you started on

Automated mode: bisect run

If you have a checker script, Git does everything on its own.

bash
git bisect start
git bisect bad
git bisect good v1.4
git bisect run ./check.sh

Script contract:

  • exit 0 - commit is good (test passed)
  • exit 1..124, 126..127 - commit is bad (test failed)
  • exit 125 - skip this commit (could not be tested)
  • any other code - fatal error, bisect stops

Pytest and most test frameworks work directly (they return 0/1):

bash
git bisect run pytest tests/test_login.py::test_password_reset

Useful commands during bisect

bash
git bisect log              # log of the current bisect session
git bisect visualize        # show the remaining commit range
git bisect skip             # skip current commit (does not build / not relevant)
git bisect reset            # exit and return to the original branch
git bisect replay <log>     # replay a session from a saved log

Custom terms

If good/bad does not fit (for example, you are looking for when a feature first appeared):

bash
git bisect start --term-old=missing --term-new=present
git bisect present
git bisect missing v1.0

Pitfalls

  • Intermediate commits do not build. Bisect requires every step to be testable. If commits are atomic (see atomic-commit) you are fine. If the history has noise, use bisect skip or exit 125 in the script.
  • Intermittent regression. If the bug appeared, disappeared, then appeared again, bisect will find some boundary but not the first one. The fix is a more precise test.
  • External dependencies. If the result depends on a package version, update dependencies in the script before the test. Otherwise bisect catches the environment change, not the commit.

§ команды

bash
git bisect start && git bisect bad && git bisect good v1.0

Start a binary search for a regression

bash
git bisect run ./test.sh

Run automated bisect with a checker script

bash
git bisect skip

Skip a commit that cannot be tested

bash
git bisect reset

End bisect and return to the original branch

§ см. также

  • blamegit blameShows for each line of a file: the commit SHA, the author, and the date of the last modification to that line. The primary answer to "who wrote this line, and when."
  • loggit logTraverses the commit graph and prints each commit. By default it starts at HEAD and follows parents. A dozen flags cover 95% of history-browsing scenarios.
  • refloggit reflogA log of all HEAD movements on this machine. By default, entries for reachable commits live for 90 days; entries for unreachable commits live for 30. The primary recovery tool after `reset --hard`, `--amend`, `rebase`, and branch deletion. Stored locally in `.git/logs/`.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies