This did not work for me when I had done something like develop > release-v1.0.0 > feature-foo
, it would go all the way back to develop, note there was a rebase involved, not sure if that is compounding my issue...
The following did give the correct commit hash for me
git log --decorate \
| grep 'commit' \
| grep 'origin/' \
| head -n 2 \
| tail -n 1 \
| awk '{ print $2 }' \
| tr -d "\n"