🔀 Git: Fix a Bisect Run Landing on an Unrelated Flaky Commit
git bisect run trusts whatever exit code your test script returns at each step, and a flaky test that fails intermittently for reasons unrelated to the actual regression — a timing-sensitive integration test, say — can get marked ‘bad’ on a commit that never introduced the real bug at all. Bisect has no way to tell a genuine regression apart from a coin-flip failure, so it confidently reports whichever commit happened to draw the bad outcome during the automated run.
🔎 The Problem
git bisect start HEAD v2.3.0 git bisect run ./run-integration-tests.sh # ... # abc123f is the first bad commit # -> turns out abc123f only touched documentation; # the integration test that failed is known to be flaky ~5% of runs
✅ Fix: Make the Script Retry Before Trusting a Failure
- Have the bisect script run the suspect test several times (3-5) and only report ‘bad’ if it fails consistently, rather than exiting on the very first failure — this filters out single-run flakiness before it ever reaches bisect’s decision logic.
- Use
git bisect skipmanually at any commit where you can independently confirm the result is unreliable (a known-flaky test, a broken unrelated build), so bisect continues searching around it instead of treating an inconclusive result as a verdict. - Where possible, replace the flaky integration test with a faster, more deterministic reproduction of just the suspected regression for the bisect run specifically — a narrower, more reliable check almost always beats a slower but shakier one for this purpose.
🚨 Why This Is Dangerous
- Reverting or investigating the commit bisect blamed, when it was actually innocent, wastes real investigation time while the true regression — introduced somewhere else in the range — keeps shipping untouched in every subsequent build.
Bisect is only as reliable as the test you hand it — ask a coin flip a question enough times and it will eventually ‘find’ a culprit.




