管道命令,用于获取带有 --no-checkout 的 git-bisect 的结果



我正在编写一个自动查找特定提交的脚本。

当我打电话给git bisect start --no-checkoutgit bisect run ./my_check_commit_script.sh时,我已经到了那个部分.它查找并显示正确的提交。但是,我不知道如何在脚本中获取此提交的哈希值。

参考BISECT_HEAD似乎仍然指向以前的old修订。 除此之外,使用git show-ref,我找到了一个 refrefs/bisect/new它似乎指向正确的提交,但我不知道我是否可以依赖它的存在。有一堆refs/bisect/old*,我怀疑只有一个refs/bisect/new可能是意外.

如何获取git bisect在我的脚本中找到的提交的哈希?


下面是一个脚本,用于创建存储库并成功调用git bisect run

git init repo
cd repo
echo a >foo
git add foo
git commit -m "Initial commit"
echo b >foo
git commit -a -m "Some commit"
echo c >foo
git commit -a -m "First commit which matches criteria"
echo d >foo
git commit -a -m "Some commit"
echo e >foo
git commit -a -m "Last commit"
git bisect start --no-checkout
git bisect old HEAD~4
git bisect new HEAD
git bisect run git merge-base --is-ancestor BISECT_HEAD HEAD~3

您找到的引用refs/bisect/new是正确的使用。命令rev-parse bisect/new保证始终返回第一个"新"提交的哈希。

Git 手册在"基本平分命令:开始、坏、好"一节中说:

最终将不再有修订需要检查,并且该命令将打印出第一次错误提交的描述。引用引用/bisect/bad 将指向该提交。

手册称其为refs/bisect/bad但因为您使用的是old&new而不是good&bad,因此引用名称也会更改。 (使用选项--term-good--term-bad,您可以将此名称更改为所需的任何名称。

最新更新