Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create tag with forward slash in its name

Tags:

git

git-tag

tags

Is there any way to create git tag with forward slash in its name when I already have the similar-looking one?

Suppose that I have "1.16.0" tag and I want to create "1.16.0/1.0.0" tag:

$ git tag "1.16.0/1.0.0"
error: 'refs/tags/1.16.0' exists; cannot create 'refs/tags/1.16.0/1.0.0'
fatal: refs/tags/1.16.0/1.0.0: cannot lock the ref
like image 711
FrozenHeart Avatar asked Sep 29 '15 17:09

FrozenHeart


1 Answers

It's not possible. See, the name of tag (any reference, in fact; the same goes with branches) is treated as the name of the file system object, created in $GIT_DIR/refs folder of your repository. This object stores the hash commit the tag is attached to.

With tag foo, it's easy - file foo is created in $GIT_DIR/refs, nothing special to wonder about.

With tag foo/bar, however, it's a bit more complicated: now folder foo is created, having just a single file - bar (again, with the hash commit). Quoting the docs:

[reference names] can include slash / for hierarchical (directory) grouping

The problem is, it's not possible to have two objects - file and folder - with the same name. So if you already have 1.16.0 tag, you won't be able to work with 1.16.0/anything. One obvious solution is transforming that initial tag into something like 1.16.0/0.0.1, then proceeding with your original intent. Or you can just replace slash with - or _.

like image 165
raina77ow Avatar answered Oct 24 '22 02:10

raina77ow