Johannes Schindelin [off-list ref] writes:
How about
oldremoteref="$(git rev-list --boundary HEAD --not \
$(git rev-list -g $remoteref | sed 's/$/^@/') |
sed -e '/^[^-]/d' -e q)"
Explanation: the "git rev-list -g $remoteref" lists the previous commits
the remote ref pointed to, and the ^@ appended to them means all their
parents. Now, the outer rev-list says to take everything in HEAD but
_not_ in those parents, showing the boundary commits. The "sed" call
lists the first such boundary commit (which must, by construction, be one
of the commits shown by the first rev-list).
Hmm, I am not sure about that "(which must..." part. When you have
Y---X
/
B---o---o---o---H
wouldn't "rev-list --boundary H --not X^@" give B, not X nor Y?