如何使用名称创建带有正斜杠的标签 [英] How to create tag with forward slash in its name

查看:78
本文介绍了如何使用名称创建带有正斜杠的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我已经拥有外观相似的git标签时,是否可以使用它来创建git标签?

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

假设我有"1.16.0"标签,并且我想创建"1.16.0/1.0.0"标签:

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

推荐答案

这是不可能的.参见,标记的名称(实际上是任何引用;分支也是如此)被视为在存储库的$GIT_DIR/refs文件夹中创建的文件系统对象的名称.该对象存储标签附加到的哈希提交.

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.

使用标签foo很容易-在$GIT_DIR/refs中创建文件foo,没什么特别的.

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

但是,使用标签foo/bar有点复杂:现在创建了文件夹 foo,它只有一个文件-bar(同样,带有哈希提交).引用文档:

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

问题是,不可能有两个具有相同名称的对象-文件和文件夹.因此,如果您已经具有1.16.0标记,则将无法使用1.16.0/anything.一种明显的解决方案是将初始标签转换为类似1.16.0/0.0.1的内容,然后继续执行您的原始意图.或者,您可以只用-_替换斜杠.

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

这篇关于如何使用名称创建带有正斜杠的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆