Find a Regression with Git Bisect
Define the regression
A regression is behavior that worked earlier but fails now. In the linear garden fixture, nine commits c0 through c8 contain notes.txt. The rule is that the watering interval must have a time unit. c0–c4 contain Water every 3 days; c5–c8 contain Water every 3. Other edits change light.txt. The goal is the first failing commit, not the most recent edit. Verify a known good and a known bad endpoint with the same repeatable test. Use a disposable checkout, with a clean index and working directory; bisect normally checks out intermediate commits in detached HEAD.
git show c0:notes.txtgit show c8:notes.txtgit status --shortNarrow the candidate range
Start the session with bad then good. Git selects a revision for testing, generally reducing the search quickly; a graph with merges is not a simple array. Run the same check at each stop: if the note has the unit, mark good; if the known missing-unit symptom occurs, mark bad. Do not mark an untestable revision bad. Repeat until Git reports the boundary. This assumes a consistent property transition; intermittent tests or a regression fixed and reintroduced may invalidate the interpretation.
git bisect start c8 c0git show -s --format=%s HEADcat notes.txtRecord and confirm
For this fixture the first bad revision is c5, whose parent c4 passes. Inspect the patch, then test both boundary snapshots again. A candidate is evidence for investigation, not proof of root cause: dependency or environment changes may matter. git bisect log records decisions; save it outside the checkout if needed. git bisect reset ends the session and returns to the original checkout by default, not a destructive git reset --hard.
git bisect loggit show c5 -- notes.txtgit show c4:notes.txtgit show c5:notes.txtgit bisect resetgit status --shortPractice
Predict the candidate interval if c4 is known good and c8 is bad. Why is c8 not automatically the first bad commit? In the manual guide classify each stop without guessing from commit messages. Record the reported commit, compare its parent and reset.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Find a Regression with Git Bisect — knowledge check
Reason about regression and historical evidence.
What makes c0 a valid good endpoint?
Which commit first lacks the unit in the fixture?
What should you do at each bisect stop?
What does bisect reset normally do?
What weakens the interpretation of a first bad boundary?