Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 948
Lukasz Avatar asked Oct 05 '10 20:10

Lukasz


People also ask

How do I tag last commit?

In order to create a Git tag for the last commit of your current checked out branch, use the “git tag” command with the tag name and specify “HEAD” as the commit to create the tag from. Similarly, if you want your tag to be annotated, you can still use the “-a” and “-m” options to annotate your tag.

How do you fetch a tag?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.

How do I list all tags?

Just type git tag (with optional -l or --list ). You can also search for tags that match a particular pattern.

How do I find my git tag list?

In order to list Git tags, you have to use the “git tag” command with no arguments. You can also execute “git tag” with the “-n” option in order to have an extensive description of your tag list. Optionally, you can choose to specify a tag pattern with the “-l” option followed by the tag pattern.


1 Answers

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.

like image 185
KARASZI István Avatar answered Sep 24 '22 03:09

KARASZI István