8

Here is the man page for git show-ref -d . They also have an example at the bottom. Still I am not able to understand what dereference does?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Nick Vanderbilt
  • 36,724
  • 29
  • 83
  • 106

1 Answers1

12

In Git, a "normal" (annotated, not lightweight) tag is an object unto itself, containing metadata and the SHA1 of the object it tags. Chapter 10.2 Git Internals - Git Objects in the Git community book has an illustration of the object model:

enter image description here

Legend: yellow - commit object, blue/green - tree object, white - blob object

So, when you use git show-ref on a normal tag, it will normally give you information about the tag object. With the -d/--dereference option, it will dereference the tag into the object the tag refers to, and provide information about it instead.

And a note on lightweight vs. annotated tags, in case you aren't aware of that: a lightweight tag is created by using git tag <tag name> (i.e. without any of the metadata-providing options like -a, -s, or -u). It's not a tag object at all, just a Git reference pointing straight to the object you've tagged. If you provide one of those options, you're attaching metadata to the tag, so Git creates a tag object to hold that.

toraritte
  • 6,300
  • 3
  • 46
  • 67
Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • Good summary.+1 See also http://stackoverflow.com/questions/1194385/seeing-what-revision-goes-with-a-tag-in-git: "if you don't know/care whether the tag is a tag object or a lightweight label but want to see just the commit you can use `git show v1.5.0^{}`, or `git rev-parse v1.5.0^{}` for a scriptable way to retrieve the commit id." – VonC Mar 28 '10 at 22:30
  • VonC's helpful hint probably looks a bit odd to anyone not very familiar with git. The `^{}` suffix is a special notation for tags; it means "dereference the tag repeatedly until you find something besides a tag" - just in case you've done something crazy like tag a tag with a tag. – Cascabel Mar 29 '10 at 05:20
  • true, the notation is odd ;) As for tagging a tag with a tag, one can imagine it could help to add some kind of metadata (like for instance a "promotion level" 'rejected', 'tested', 'released', ...) to an existing tagged commit. – VonC Mar 29 '10 at 07:24