有个回归在几十个提交里找,手动来回切分支挺磨人。只要能写出一个返回退出码的检查脚本,Git 可以自己二分:
#!/usr/bin/env bash
npm test -- --runInBand test/parser.test.js >/dev/null 2>&1
保存成 check-regression.sh 后:
chmod +x check-regression.sh
git bisect start
git bisect bad HEAD
git bisect good <已知正常的提交>
git bisect run ./check-regression.sh
git bisect reset
环境:Git 2.x、Bash,以及项目本身可用的测试命令。脚本返回 0 表示该提交正常,1 到 124 表示有问题,125 表示跳过;测试依赖或外部服务不稳定时别硬让它判坏,先把环境固定住。git bisect run 结束后记得 git bisect reset 回到原分支。