Get last git tag from current commit

I am trying to get the last git tag from a specific point in my tree.

The tree is as follows:

* 334322c|2016-12-06| (tag: 0.1265, tag: 0.1264) (18 hours ago)
* 739392e|2016-12-06| (HEAD -> testbranch, tag: 0.1263, tag: 0.1262) (19 hours ago)
* 8ec1add|2016-12-06| (tag: 0.1261, tag: 0.1260, tag: 0.1259) (20 hours ago)
* 5b2667b|2016-12-06| (tag: 0.1258) (21 hours ago)
* c7ff4bc|2016-12-06| (tag: 0.1257, tag: 0.1256) (22 hours ago)

0.1263 is the git tag I'm looking for.

When in 739392eusing git describe --tagsonly returns 0.1262, which is the first tag of this commit, and I do not get all the candidates.

When in 739392ewith the help is git describe --tags $(git rev-list --tags --max-count=1)returned 0.1265, the last tag in the tree (regardless of where the HEAD is located).

+4
source share
1 answer

You can use a subcommand git tag with a list option indicating the specific commit you are checking:

git tag -l --points-at <commit|object>

git 2.0 , --sort, , .

0

Source: https://habr.com/ru/post/1663072/


All Articles