Reputation: 3745
We're using multiple tag identifiers in our repo. Eg. ABC-1.3.5.234 and DEF-1.2.1.25. The describe command gives me almost what I want:
git describe --long
ABC-1.3.5.234-33-deadbeef
But I really wanted to know the value relative to the most recent DEF tag in my history. Is there a way to specify which tag I want to use as the base for calculating relative distance? Can I do it with a regex?
Upvotes: 4
Views: 1427
Reputation: 1323553
The git describe
man page is clear:
If an exact match was not found, git describe will walk back through the commit history to locate an ancestor commit which has been tagged. The ancestor's tag will be output along with an abbreviation of the input committish's SHA-1.
If multiple tags were found during the walk then the tag which has the fewest commits different from the input committish will be selected and output.
Here fewest commits different is defined as the number of commits which would be shown bygit log tag..input
will be the smallest number of commits possible.
So you might have to write a script which:
git describe
git describe
that commitn
' of additional commits on top of the found tagged objects during that loopDEF-xxx-n-DEF_SHA1
.Since 2013, as illustrated in Hendrik's answer, this work better:
git describe --all --match <tagPattern>
But only if, as I describe in "how to match a hidden ref using git describe", you are using Git 2.15 (Q3 2017).
Before 2.15, --all
would have been ignored.
Note: Git 2.15 also allows multiple patterns for git describe --match
That allows even more advanced searches like:
For example, suppose you wish to find the first official release tag that contains a certain commit.
If we assume that official release tags are of the form "v*
" and pre-release candidates include "*rc*
" in their name, we can now find the first release tag that introduces the commitabcdef
:
git describe --contains --match="v*" --exclude="*rc*" abcd
Upvotes: 4
Reputation: 11
For me
> git describe --all --match "<tag>"
tags/v0.0.0pre1-334-gbb55666
did the trick.
--all
enables the search for all references not just tagged ones
--match "<tag>"
specifies the tag to be used to calculate the distance.
Upvotes: 1
Reputation: 11
Just stumbled upon this question. This might help:
git describe --match "DEF-*"
Upvotes: 1