Isolating with Bisection

💤0
Lv 10 XP
← 🧱 Foundations · Troubleshooting Mindset

Isolating with Bisection

Intermediate ⭐ 80 XP ⏱ 15 min #troubleshooting#bisection#git

Halve the search space repeatedly to pinpoint what broke — including with git bisect.

📖Theory

Bisection is binary search applied to debugging. Instead of inspecting every possibility, you repeatedly split the search space in half and ask “is the problem before or after this point?” Each test eliminates half the candidates, so even hundreds of commits or config lines collapse to a handful of checks.

You bisect across time (which commit introduced the bug?), space (which half of the config/file?), and components (disable half the services). Git automates the commit case with git bisect: you mark a known-good and a known-bad commit, and it checks out the midpoint for you to test.

🌍Real-World Example
git bisect start
git bisect bad                 # current commit is broken
git bisect good v1.2.0         # this old tag worked
# Git checks out the midpoint — test it, then:
git bisect good                # or: git bisect bad
# ...repeat until Git names the first bad commit...
git bisect reset               # return to where you were

Non-code bisection: comment out half a config, retest; if fixed, the problem was in that half — narrow again.

✍️Hands-On Exercise
  1. Use git bisect on a repo to find a commit that introduced a change.
  2. Describe how you’d bisect a 200-line config file to find a bad setting.
  3. Calculate how many steps it takes to bisect 256 candidates.
  4. Explain when bisection beats reading code top-to-bottom.
🧾Cheat Sheet
TaskCommand / idea
Startgit bisect start
Mark current badgit bisect bad
Mark known goodgit bisect good <ref>
Continuemark each checkout good/bad
Finishgit bisect reset
Automategit bisect run <test-cmd>
Config/spacedisable half, retest
💬Common Interview Questions
What is bisection in troubleshooting?

Binary search for the cause: repeatedly split the search space in half and test which half contains the problem, eliminating half the candidates each step.

How does git bisect help find a regression?

You mark a good and a bad commit; git checks out the midpoint for you to test and narrows down, in log2(N) steps, to the exact commit that introduced the bug.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type