hewking.top

hewking's blog

View the Project on GitHub hewking/blog

git bisect 用法

Author: hewking
Labels: blog
Created: 2024-12-20T11:44:40Z
Link and comments: https://github.com/hewking/blog/issues/26

git bisect 用法

以下是使用 git bisect 查找 bug 的方法:

  1. 开始二分查找:
git bisect start
  1. 标记当前版本为有问题:
git bisect bad
  1. 标记一个已知的正常版本(可以用 commit hash 或 tag):
git bisect good <commit-hash>
  1. Git 会检出中间的提交。测试 bug 是否存在,然后标记:
git bisect good  # 如果 bug 修复了
# 或
git bisect bad   # 如果 bug 还在
  1. 重复步骤 4,直到 git 找到第一个有问题的提交

  2. 完成后,重置二分查找:

git bisect reset

实用技巧:

测试脚本示例:

#!/bin/sh
# test-script.sh
make && ./my-test
exit $?  # 测试失败返回非零值

来源: