Find the commit that broke a test with git bisect
Mark a known good and bad version, then narrow the interval in an isolated checkout.
The problem
A product-preview test passed in the last release and fails today. Dozens of commits sit between those releases. Walking them one by one takes time. Use a reproducible test to search the history.
The tool
git bisect applies binary search between a known good and known bad version. Run the same check at each selected commit and mark the outcome.
The steps
- Begin in a clean, isolated checkout. Record the preview command and remove dependencies on today's date or a changing database.
- Confirm the test passes at an older tag and fails at the current version. Record both identifiers instead of assuming the older tag is good.
- Run
git bisect start, followed bygit bisect bad HEADwhile HEAD is the bad version andgit bisect good v1.3.0if you verified that tag. - On each selected version, run the same test. Mark
git bisect goodfor a pass andgit bisect badfor the specific regression. - Use
git bisect skipif an unrelated build problem makes the version untestable. Record the reason. Skips near the boundary can leave more than one candidate. - Record the indicated change, compare it with its relevant parent and run
git bisect resetto return. Include the test command and outcome in the issue.
The real cost
Git includes bisect. Most cost comes from rerunning the check across differing dependencies, so isolate the smallest deterministic test.
The free alternative
For two adjacent changes, manual comparison might be quicker. A wider range makes a binary search useful.
Notes
- We have not tried these steps ourselves yet. They are based on the official docs. Button names may change. If your interface differs, follow the docs.
- The resulting commit is a starting point for investigation. Confirm that its behavior explains the reported symptoms.
- Keep old revisions away from production data. Use a fixture and a distinct working directory.
Sources
Did you like this guide?
The weekly newsletter is being prepared. Leave your email and we'll send it when it launches.
We use your email only to send the newsletter. Privacy policy
