自动找出引入错误的提交
使用二分搜索算法和给定的脚本来找出历史记录中引入错误的提交。
- 使用
git bisect start开始该过程。 - 使用
git bisect good <commit>将<commit>标记为“good”,表示已知它是没有错误的。 - 使用
git bisect bad <commit>将另一个<commit>标记为“bad”,表示它有错误。 - 使用
git bisect run <command>在每个后续提交上运行给定的<command>,以找出引入错误的提交。 - 使用
git bisect reset重置到原始分支。您可以选择指定一个<commit>进行重置。
git bisect start
git bisect good <commit>
git bisect bad <commit>
git bisect run <command>
git bisect reset [<commit>]
# 示例
git bisect start
git bisect good 3050fc0de
git bisect bad c191f90c7
git bisect run npm test # 对每个提交运行 `npm test`
# ... 一段时间后,将打印出错误的提交
git bisect reset # 返回原始分支