Reputation: 171
I'm trying to add an extra tag for the commit to be able later to select this commit by git describe
with --match
pattern;
When I use --match
to catch usual commits with one tag everything works fine.
But when I try to --match commit with two tags by pattern "deployed", I get very weird tag like, for example:
I have commit: b946bdf (tag: [email protected]) Publish
I add "deployed" tag: b946bdf (tag: [email protected], tag: deployed) Publish
Then I run git describe --abbrev=0 --match "deployed"
And the result of this command is [email protected]
If I try to use --abbrev=1
I get [email protected]
And the most interesting that the -9-g1e5c94cc55fded72114b801bd47d8d29e7721255
is not even a has of this commit. I have no idea why and where from I get this weird identifier.
I want to get a clean tag like [email protected]
What I'm doing wrong?
Upvotes: 0
Views: 1081
Reputation: 52006
If your intention is to get the hash of the commit tagged by deployed
, just use git rev-parse
:
# works for any type of tag :
git rev-parse deployed^{}
# works if 'deployed' is a plain tag :
git rev-parse deployed
If deployed
is an annotated tag, git rev-parse deployed
(without the ^{}
) will give you the hash of the tag object itself, not the hash of the commit that is tagged.
this doesn't explain the weird output you get from git describe
, but I thought it was worth mentioning this command.
Upvotes: 0
Reputation: 489203
The --match
option to git describe
takes a shell-style glob pattern, such as a*z
. It then runs the tags listed by git tags
through a shell-style matcher.1 Hence, given the glob pattern a*z
, tags named abuzz
and aveloz
would match, but a tag named arbiter
or fuzz
would not.
Your glob pattern is deployed
, and since there are no wildcard characters allowed, the only allowed tag by this --match
option is deployed
itself. You do have a tag named deployed
, and you gave only one --match
, so this is the only one allowed.
If I create such a tag, I can use it:
$ git tag -a deployed -m silly
$ git describe --abbrev=0 --match deployed
deployed
This tag can't be used for any earlier revision, of course:
$ git describe --abbrev=0 --match deployed HEAD~
fatal: No tags can describe '98f3f03bcbf4e0eda498f0a0c01d9bd90de9e106'.
Try --always, or create some tags.
Deleting the tag produces an appropriate error:
$ git tag -d deployed
Deleted tag 'deployed' (was a464a376ca)
$ git describe --abbrev=0 --match deployed
fatal: No names found, cannot describe anything.
I cannot explain your output. There have been bugs in git describe
; the release notes for Git 2.15.0 point one out, for instance. But this would not produce the output you show (I think). What version of Git are you using?
1This is actually all built in to git describe
itself, which doesn't have to run git tags
. The effect is the same, though. Note that shell glob patterns may need quoting to protect them from the shell, depending on your shell.
Upvotes: 0