Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Git tag listing

AntonioVecchio April 2, 2019

Hi all, usually I list tags via the command git tag -l.

Is there any way to get separated list either just of annotated tags or just of lightweight tags?

Thanks in advance.

Antonio

1 answer

1 accepted

1 vote
Answer accepted
Tyler T
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2019

Great question. I'm not sure you can get that granular using git alone. This is from the docs:

You can also search for tags that match a particular pattern. The Git source repo, for instance, contains more than 500 tags. If you’re interested only in looking at the 1.8.5 series, you can run this:

$ git tag -l "v1.8.5*"
v1.8.5
v1.8.5-rc0
v1.8.5-rc1
v1.8.5-rc2
v1.8.5-rc3
v1.8.5.1
v1.8.5.2
v1.8.5.3
v1.8.5.4
v1.8.5.5

Source: https://git-scm.com/book/en/v2/Git-Basics-Tagging

AntonioVecchio April 3, 2019

Hi Tyler, I already studied the official documentation. Indeed in official documentation is written

"Tag objects (created with -a, -s, or -u) are called "annotated" tags; they contain a creation date, the tagger name and e-mail, a tagging message, and an optional GnuPG signature. Whereas a "lightweight" tag is simply a name for an object (usually a commit object)."

Well, I found that, both for an annotated tag and for a lightweight tag, git creats a file inside /ref/tags folder.

Further, git log command doesn't distinguish between an annotated tag and a lightweight tag.

So ... in which way can I understand the type (annotated or lightweight) of an already existing tag? This is again my original question.

Any further suggestion?

Kind Regards.

Antonio

Tyler T
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2019

For annotated tags

You can see the tag data along with the commit that was tagged by using the git show command:

For lightweight tags

if you run git show on the tag, you don’t see the extra tag information. The command just shows the commit:

Your recent question:

in which way can I understand the type (annotated or lightweight) of an already existing tag?

Use `git show` and reference the output (differences noted above).

git show <existing-tag-name>

Your original question:

Is there any way to get separated list either just of annotated tags or just of lightweight tags?

Again, I'm not sure this can be achieved with git commands but perhaps a custom script could be a solution.

AntonioVecchio April 4, 2019

Hi Tyler, I tried what you suggested: unfortunately git show <tag-name> is not useful because its output is the same for annotated and lighweight tags.

However using git tag -l -n is useful because it shows the related commit messages for lightweight tags, so I can compare the messages of all tags with the message of the related commit: assuming reasonably that annotated tags are used to enrich the commit and so they have a message different from the message of the commit, in this way I can deduce which are lightweight tags and which are annotated ones.

This is not the cleaned solution I was searching for, however thank you very much.

Regards.

Antonio

AntonioVecchio April 5, 2019

Hi Tyler, I found an interesting, easy and quick workaround: it's confortable to use git cat-file -p for each tag, so the difference between an annotated tag and a lightweight one is glaring. :-)

Bye.

Antonio

Like Tyler T likes this
Tyler T
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 5, 2019

Nice! Thanks for sharing that.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events