So it's not pretty, but this is what I've come up with.
#! /bin/sh
commit=$(git rev-parse HEAD)
while [ "$(git log --format="%p" -1 $commit | wc -w)" -eq 1 ] \
&& [ "$(git branch --all --contains $commit | wc -l)" -eq 1 ]
do
commit=$(git rev-parse "$commit^")
done
echo $commit
I'm sure there's a simpler, more robust way of accomplishing this, but it seems to do what I want. Suggestions and improvements are very much welcome. (It'd be nice to do this with just Git plumbing instead of relying on wc
, for example.)