Use git describe
. The output looks like this: v5.19.5-55-ga854082
, a committish with three parts: v5.19.5
is the most recent tag in the current branch, 55
is the number of commits since this tag, and ga854082
is an abbreviated SHA1 with a preceding g
. The number of commits may be used for checking if something is newer.
(The git describe
output above is actually a real world example from the perl source code)