10

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 

1 Answer 1

14

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 _.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.