#!/bin/sh # Print a version string. # Traverse all tags, # Find common ancestor of HEAD and tag, # Count number of commits between this ancestor and HEAD # Find tag with mininum count # Produce a --g string a la git describe H=$(git rev-parse --short HEAD) CT=$(for F in $(git tag -l) ;do echo $(git rev-list $(git merge-base $F HEAD)..HEAD |wc -l) $F $H ;done | sort -n | head -n 1 ) echo $CT $H | awk '{print $2 "-" $1 "-g" $3}'