garen96
garen96

Reputation: 185

How to remove a tag which name includes braces?

Show tags on remote

$ git ls-remote --tags origin
.....
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/tags/v1.0.7^{}
.....

How to remove this tag?

I have tried:

$ git push --delete origin v1.0.7^{}
fatal: invalid refspec ':v1.0.7^{}'

Upvotes: 1

Views: 236

Answers (1)

torek
torek

Reputation: 488223

The tag name is v1.0.7.

When you use git ls-remote, Git shows you both the target object of the tag itself, and the more-base object to which the tag points. If the tag is a lightweight tag, these two are by definition the same thing, and you see only one item:

04c6e9e9ca34226db095bbaa1218030f99f0b7c6    refs/tags/foo

When the tag is an annotated tag, however, the object to which it points is a an annotated tag object—it must be, by definition, since otherwise the tag would be a lightweight tag—and that annotated tag object has another underlying object.

The syntax for finding the underlying object is to suffix the tag name with ^{}, as described in the gitrevisions documentation:

<rev>^{}, e.g. v0.99.8^{}
A suffix ^ followed by an empty brace pair means the object could be a tag, and dereference the tag recursively until a non-tag object is found.

Hence:

$ git rev-parse v2.21.0
2bb64867dc05d9a8432488ddc1d22a194cee4d31
$ git rev-parse v2.21.0^{}
8104ec994ea3849a968b4667d072fedd1e688642

and:

$ git show v2.21.0 | head -3 | sed 's/@/ /'
tag v2.21.0
Tagger: Junio C Hamano <gitster pobox.com>
Date:   Sun Feb 24 07:55:39 2019 -0800
$ git show v2.21.0^{} | head -3 | sed 's/@/ /'
commit 8104ec994ea3849a968b4667d072fedd1e688642
Author: Junio C Hamano <gitster pobox.com>
Date:   Sun Feb 24 07:55:19 2019 -0800

Here v2.21.0 is the tag. That name identifies internal Git object 2bb64867dc05d9a8432488ddc1d22a194cee4d31 which is an annotated tag object:

$ git cat-file -t 2bb64867dc05d9a8432488ddc1d22a194cee4d31
tag

The tag object then goes on to identify the commit object 8104ec994ea3849a968b4667d072fedd1e688642. The output from git ls-remote therefore includes:

2bb64867dc05d9a8432488ddc1d22a194cee4d31        refs/tags/v2.21.0
8104ec994ea3849a968b4667d072fedd1e688642        refs/tags/v2.21.0^{}

The first is the tag; the second is the underlying commit. The one tag name v2.21.0 means both things, depending on how you ask Git about it.

Upvotes: 2

Related Questions