Search code examples
regexgittagsfindtagging

How to get last Git tag matching regex criteria


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?


Solution

  • Use the following command:

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

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

    NOTE: --match accepts a glob, not a regex, and therefore the command shown may match other tags, e.g. v1234_this_matches_too.