I'm writing a script which automatically finds a specific commit.
I've reached the part when I'm calling git bisect start --no-checkout and git bisect run ./my_check_commit_script.sh. It finds and displays the correct commit. However, I don't know how can I get the hash of this commit in my script.
The reference BISECT_HEAD seems to still point at the previous old revision.
Other than that, using git show-ref, I've found a ref refs/bisect/new which seems to point to the correct commit but I don't know if I can rely on it existing. There is a bunch of refs/bisect/old* and I suspect it may be an accident that there is only a single refs/bisect/new.
How can I get the hash of the commit found by git bisect in my script?
Here is a script that crates a repository and successfully calls git bisect run on it:
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
The reference
refs/bisect/newthat you've found is the correct one to use. The commandrev-parse bisect/newguarantees to always return the hash of the first "new" commit.The Git manual tells that in the section "Basic bisect commands: start, bad, good" (emphasis mine):
The manual calls it
refs/bisect/badbut because you're usingold&newinstead ofgood&bad, the reference name also changes. (Using options--term-goodand--term-badyou can change this name to anything you want.)