home | list info | list archive | date index | thread index

[OCLUG-Tech] more git Q: lightweight vs annotated tags

  again, a curiosity about a fairly simple issue -- all the docs
define the two types of tags:

1) annotated -- an actual git commit object with an author and so on
2) lightweight -- little more than a commit ID stored under refs/tags

or so i thought.

  i wanted to demonstrate the difference using the linux kernel source
tree, so if you list *all* the tags, well, it is of course lengthy:

$ git tag -l | wc -l
465
$

now to demonstrate the difference, i was going to display the contents
of .git/refs/tags to show it was (i thought) empty, but:

[rpjday@localhost git]$ ls -l .git/refs/tags/
total 12
-rw-rw-r--. 1 rpjday rpjday 41 Apr 13 06:38 v4.0
-rw-rw-r--. 1 rpjday rpjday 41 Apr  7 05:47 v4.0-rc7
-rw-rw-r--. 1 rpjday rpjday 41 Apr 28 10:38 v4.1-rc1
$

huh? are those supposed to represent the three lightweight tags that
currently exist? *i* certainly didn't add them. so they're part of the
checkout? did someone just make a mistake and add lightweight tags
rather than annotated ones?

  more confusing is what i read in a bit at stack overflow:

http://stackoverflow.com/questions/21031201/how-can-i-list-all-lightweight-tags

"As for annotated tags, well, the trick here—it affects the
"lightweight" tags part too—is that an annotated tag is actually an
object in the git repository, but, there's a lightweight tag that
points to that object, that lets you get at the annotated tag by its
tag name.1 So it's really a pair of things: a lightweight tag, plus
the in-repo annotated tag object, that makes it "not a lightweight
tag", except for that stubborn fact that it is a lightweight tag at
the same time!

"Thus, it boils down to: find all lightweight tags, then optionally
select only tags pointing to commits or tags pointing to tag-objects
depending on the behavior you want, then go on to emit the tag name."

  i never knew this, but that makes it even *more* confusing as it
suggests there should be all 465 tag entries under .git/refs/tags/,
no? so how do i interpret those lonely three tag names in refs/tags?

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================