34 / 57 · 17 Git & Version Control · Bisect and Cherry-Pick← prev⊞ allnext →☰ Read as one page
5.4Automated Bisect
The real power of bisect is automation. Give Git a command that exits with 0 (good) or non-zero (bad), and it runs the entire bisect automatically.
# Fully automated bisect
git bisect start HEAD v2.3.0
git bisect run npm run test:checkout
# Or with a specific test file
git bisect start HEAD v2.3.0
git bisect run npx playwright test tests/checkout.spec.ts
# Using a custom script for more complex checks
git bisect start HEAD v2.3.0
git bisect run ./scripts/bisect-test.sh
A practical bisect script that handles setup:
#!/bin/bash
# scripts/bisect-test.sh
# Install dependencies (they may differ between commits)
npm ci --silent 2>/dev/null
# Run the specific test
npx playwright test tests/checkout.spec.ts --reporter=list 2>/dev/null
# Exit code 0 = good, non-zero = bad
# Exit code 125 = skip (cannot test this commit, e.g., build fails)
Exit code 125 tells bisect to skip this commit (the commit cannot be tested, perhaps because it does not compile). Bisect continues with the next candidate.