Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if a given git tag is annotated or lightweight?

Tags:

git

git-tag

I type git tag and it lists my current tags:

1.2.3 1.2.4 

How can I determine which of these is annotated, and which is lightweight?

like image 310
G. Sylvie Davies Avatar asked Nov 08 '16 05:11

G. Sylvie Davies


People also ask

Are github tags lightweight or annotated?

Git supports two types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn't change — it's just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database.

What is a lightweight tag in git?

Lightweight tags are the simplest way to add a tag to your git repository because they store only the hash of the commit they refer to. They are created with the absence of the -a, -s, or -m options and *do not* contain any extra information.

What is the difference between annotated and unannotated tags?

TL;DR. The difference between the commands is that one provides you with a tag message while the other doesn't. An annotated tag has a message that can be displayed with git-show(1), while a tag without annotations is just a named pointer to a commit.

How do I see a git tag message?

Find Latest Git Tag Available In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.


1 Answers

git for-each-ref tells you what each ref is to by default, its id and its type. To restrict it to just tags, do git for-each-ref refs/tags.

[T]he output has three fields: The hash of an object, the type of the object, and the name in refs/tags that refers to the object. A so-called "lightweight" tag is a name in refs/tags that refers to a commit¹ object. An "annotated" tag is a name in refs/tags that refers to a tag object.

- Solomon Slow (in the comments)

Here is an example:

$ git for-each-ref refs/tags                                            902fa933e4a9d018574cbb7b5783a130338b47b8 commit refs/tags/v1.0-light 1f486472ccac3250c19235d843d196a3a7fbd78b tag    refs/tags/v1.1-annot fd3cf147ac6b0bb9da13ae2fb2b73122b919a036 commit refs/tags/v1.2-light 

To do this for just one ref, you can use git cat-file -t on the local ref, to continue the example:

$ git cat-file -t v1.0-light commit $ git cat-file -t v1.1-annot tag 

¹ tags can refer to any Git object, if you want a buddy to fetch just one file and your repo's got a git server, you can git tag forsam :that.file and Sam can fetch it and show it. Most of the convenience commands don't know what to do with tagged blobs or trees, but the core commands like update-index and such do

like image 155
jthill Avatar answered Sep 28 '22 11:09

jthill