3

What is the meaning of the symbol ^{}?
If I check with git log or github the tag reference to the commit in the lines with this symbol, so what is the duplicate object without this symbol.

Example

2191702bddc9438e2e8beda602972fdb87a73a15        refs/tags/V1.0
0bfeb6f7a1d2789b3e3d9944edbe680cd7355b6a        refs/tags/V1.0^{}
6bde933efef11bbc75f71df2111b146748220ad8        refs/tags/V2.0
de33c8da37dba18f8d134f6a2a4c1e70da5593ae        refs/tags/V2.0^{}
  • `^{}` is the syntax to *dereference* something (tag, branch) to the commit it ultimately points to. In the case of branch `abc`, `abc^{}` means "the commit which branch abc is currently pointing to" – Romain Valeri Dec 21 '21 at 14:16
  • What command did you run to get that output? The `^{}` syntax resolves an "annotated tag" to its "underlying object" (see for instance https://stackoverflow.com/questions/49283734/why-isnt-my-tag-listed-when-i-checkout-with-git-gui#49286861 and https://stackoverflow.com/questions/43858778/type-commit-in-an-annotated-tag-in-git/43859023), but I'm not sure if what you're seeing is actual duplicate tags, or two lines for each tag. – IMSoP Dec 21 '21 at 14:16
  • Looks like `0bfeb6f7` is the commit object which is referenced by the above tag object (`2191702bd`). Same for the second tag and its target commit. – Romain Valeri Dec 21 '21 at 14:19
  • 1
    @IMSoP the command was `git ls-remote --tags` – yaron samuel Dec 21 '21 at 14:52
  • @yaronsamuel See [`git help revisions`](https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltrevgtemegemv0998em). – phd Dec 21 '21 at 14:56

2 Answers2

2

These are annotated tags.

The other type, a lightweight tag, is a name that refers to a commit. The tag itself doesn't exist as a separate object in the git repository, but it's just an alternative name for a normal commit object.

You would just have 1 line for each such tag in your listing there, something like:

1234567890c9438e2e8beda602972fdb87a73a15        refs/tags/lightweight

As a git graph you could think of something like this:

                       master
                         v
*----*----*----*----*----*
                    ^
                  v9.1

However, the presence of two lines, one of them with that ^{} syntax, means that these tags are annotated tags.

These exist as their own separate objects in the git repository and also refer to a regular commit object.

So with these two lines:

2191702bddc9438e2e8beda602972fdb87a73a15        refs/tags/V1.0
0bfeb6f7a1d2789b3e3d9944edbe680cd7355b6a        refs/tags/V1.0^{}

This means that the annotated tag object is in the object with id 2191702..., whereas that tag object refers to commit 0bfeb6f7a....

                       master
                         v
*----*----*----*----*----*
                    |
                 tag-object
                    ^
                  V1.0

TL,DR: Lightweight tags would show only the first line, the presence of the second line means these are annotated tags where the tag-name refers to an annotated tag object, and the second reference with ^{} denotes the commit the tag refers to.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • Thanks for your useful answer. There is a reason to prefer annotated tags and not lightweight tags? – yaron samuel Dec 22 '21 at 13:07
  • A lightweight tag is just an alternative name for a commit. An annotated tag can have a message and will have an author and a timestamp. Annotated tags can also be signed. – Lasse V. Karlsen Dec 23 '21 at 08:36
0

Git 2.42 (Q3 2023) officially documents git ls-remote output format, including the ^{} lines:

See commit 51f9d2e, commit a5b0763, commit e959fa4, commit 21c9bac, commit 00bf685 (19 May 2023) by Sean Allred (vermiculus).
See commit 0f45b5b (19 May 2023) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit ebd07c9, 13 Jun 2023)

ls-remote doc: document the output format

Signed-off-by: Sean Allred

While well-established, the output format of ls-remote was not actually documented.
This patch adds an OUTPUT section to the documentation following the format of git-show-ref.txt (which has similar semantics).

Add a basic example immediately after this to solidify the 'normal' output format.

git ls-remote now includes in its man page:

OUTPUT

The output is in the format:

<oid> TAB <ref> LF

When showing an annotated tag, unless --refs is given, two such lines are shown:

  • one with the refname for the tag itself as <ref>,
  • and another with <ref> followed by ^{}.
    The <oid> on the latter line shows the name of the object the tag points at.

git ls-remote now includes in its man page:

  • List all references (including symbolics and pseudorefs), peeling tags:
$ git ls-remote
27d43aaaf50ef0ae014b88bba294f93658016a2e  HEAD
950264636c68591989456e3ba0a5442f93152c1a  refs/heads/main
d9ab777d41f92a8c1684c91cfb02053d7dd1046b  refs/heads/next
d4ca2e3147b409459955613c152220f4db848ee1  refs/tags/v2.40.0
73876f4861cd3d187a4682290ab75c9dccadbc56  refs/tags/v2.40.0^{}

And:

ls-remote doc: show peeled tags in examples

Signed-off-by: Sean Allred

Without --refs, this command will show peeled tags.
Make this clearer in the examples to further mitigate the possibility of surprises in consuming scripts.

git ls-remote now includes in its man page:

485a869c64a68cc5795dd99689797c5900f4716d  refs/tags/v2.39.2
cbf04937d5b9fcf0a76c28f69e6294e9e3ecd7e6  refs/tags/v2.39.2^{}
d4ca2e3147b409459955613c152220f4db848ee1  refs/tags/v2.40.0
73876f4861cd3d187a4682290ab75c9dccadbc56  refs/tags/v2.40.0^{}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250