What names are valid git tags?

断了今生、忘了曾经 提交于 2019-12-03 04:08:54
Willem Van Onsem

You can check if the name is valid with

git check-ref-format

This page contains the constraints on a valid name. Quoted from the page (possibly outdated in the future):

  1. They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.

  2. They must contain at least one /. This enforces the presence of a category like heads/, tags/ etc. but the actual names are not restricted. If the --allow-onelevel option is used, this rule is waived.

  3. They cannot have two consecutive dots .. anywhere.

  4. They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.

  5. They cannot have question-mark ?, asterisk *, or open bracket [ anywhere. See the --refspec-pattern option below for an exception to this rule.

  6. They cannot begin or end with a slash / or contain multiple consecutive slashes (see the --normalize option below for an exception to this rule)

  7. They cannot end with a dot ..

  8. They cannot contain a sequence @{.

  9. They cannot be the single character @.

  10. They cannot contain a \.

As you can see, in your case you violated rule (5).

You can use the --normalize flag to normalize tags with respect to slashes (removing leading slashes as well as consecutive ones):

git check-ref-format --normalize "tags/weird//tag"

The tags/ part species that you are validating a tag.

After some discussion with @NikosAlexandris, you can write the following one liner to check the tag <some-tag> with textual feedback:

git check-ref-format "tags/<some-tag>" && echo "Valid tag" || echo "Invalid tag"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!