哪些名称是有效的 git 标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26382234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What names are valid git tags?
提问by Aik
I have got a error message while creating tag containing [
character:
我在创建包含[
字符的标签时收到一条错误消息:
fatal: '[' is not a valid tag name.
致命:“[”不是有效的标记名称。
Question: are there any rules for tags in the git?
问题:git 中的标签有什么规则吗?
回答by Willem Van Onsem
You can check if the name is valid with
您可以检查名称是否有效
git check-ref-format
This pagecontains the constraints on a valid name. Quoted from the page (possibly outdated in the future):
此页面包含对有效名称的限制。从页面引用(将来可能会过时):
They can include slash
/
for hierarchical (directory) grouping, but no slash-separated component can begin with a dot.
or end with the sequence.lock
.They must contain at least one
/
. This enforces the presence of a category likeheads/
,tags/
etc. but the actual names are not restricted. If the--allow-onelevel
option is used, this rule is waived.They cannot have two consecutive dots
..
anywhere.They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177
DEL
), space, tilde~
, caret^
, or colon:
anywhere.They cannot have question-mark
?
, asterisk*
, or open bracket[
anywhere. See the--refspec-pattern
option below for an exception to this rule.They cannot begin or end with a slash
/
or contain multiple consecutive slashes (see the--normalize
option below for an exception to this rule)They cannot end with a dot
.
.They cannot contain a sequence
@{
.They cannot be the single character
@
.They cannot contain a
\
.
它们可以包含
/
用于分层(目录)分组的斜杠,但斜杠分隔的组件不能以点开头.
或以序列 结尾.lock
。它们必须至少包含一个
/
. 这会强制存在诸如等之类的类别heads/
,tags/
但实际名称不受限制。如果使用该--allow-onelevel
选项,则放弃此规则。他们不能在
..
任何地方有两个连续的点。它们在任何地方都不能有 ASCII 控制字符(即值低于 \040 或 \177 的字节
DEL
)、空格、波浪号~
、插入符号^
或冒号:
。它们不能在任何地方有问号
?
、星号*
或左括号[
。有关--refspec-pattern
此规则的例外情况,请参阅下面的选项。它们不能以斜杠开头或结尾,也不能
/
包含多个连续的斜杠(有关--normalize
此规则的例外情况,请参阅下面的选项)它们不能以点结尾
.
。它们不能包含序列
@{
。它们不能是单个字符
@
。它们不能包含
\
.
As you can see, in your case you violated rule (5).
如您所见,在您的情况下,您违反了规则 (5)。
You can use the --normalize
flag to normalize tags with respect to slashes (removing leading slashes as well as consecutive ones):
您可以使用该--normalize
标志来规范化与斜杠相关的标签(删除前导斜杠以及连续的斜杠):
git check-ref-format --normalize "tags/weird//tag"
The tags/
part species that you are validating a tag
.
该tags/
部分物种是验证tag
。
After some discussion with @NikosAlexandris, you can write the following one liner to check the tag <some-tag>
with textual feedback:
在与@NikosAlexandris 进行了一些讨论后,您可以编写以下一行代码来检查<some-tag>
带有文本反馈的标签:
git check-ref-format "tags/<some-tag>" && echo "Valid tag" || echo "Invalid tag"