How to create tag with forward slash in its name

你离开我真会死。 提交于 2019-12-23 07:47:54

问题


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:


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



来源:https://stackoverflow.com/questions/32849840/how-to-create-tag-with-forward-slash-in-its-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!