How to get last Git tag matching regex criteria

Lukasz picture Lukasz · Oct 5, 2010 · Viewed 32.5k times · Source

I need Git command to get/find last tag starting with 'v' to get last versioning commit (I am using tags with v letter at the beginning to tag next application version (example: v0.9.1beta).

Is there any way to do it?

Answer

KARASZI István picture KARASZI István · Oct 5, 2010

I'm using the following command for this:

git describe --match "v[0-9]*" --abbrev=4 HEAD

It will also modify the version if you did something with the source tree since your last versioned tag.

Please note that this is not a regex but a glob but works for the provided example.