Which characters are illegal within a branch name?
分支名称中哪些字符是非法的?
- 根据thread stackoverflow.com/questions/16862933/…,逗号也是非法的。
refname的命名规则:
Git imposes the following rules on how references are named:
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 like heads/, 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 \.
除此之外,分支名称的附加规则:
They cannot start with a dash -
感谢Jakub Nar?bski,git check-ref-format的手册页有更多的细节。
- 值得一提的是,允许使用">",但要切换到bash中的分支,则需要使用前面的""进行转义。
- 我在分支名称中使用逗号时遇到问题,但不要认为这是在手册页上不允许列出的。有人肯定知道吗?
- 我对你链接的手册页中的规则2感到困惑。上面写着"2"。它们必须至少包含一个/。"请解释一下?我的分支机构都没有一个名称是/。
- @chharvey:一个没有/的"分支"已经"自动"为它准备了heads/。实际上:如果没有/,还不清楚它是一个分支、一个标签还是其他什么东西…
- @dmtinner:允许使用逗号。
- 也有一些字符在Windows上会导致错误,但在Mac/Linux上有效,例如",这有时会给我们带来问题;如果推送这样的分支,在Windows用户能够再次获取之前,必须在主存储库上重命名或删除它。或者,如果Git本身支持Windows上分支名称中的引号,它可能是Windows上的egit或jgit错误。
- 为了使分支名称具有健全性、简洁性、可预测性(以及可移植性:对于分支名称上的脚本,我只在分支名称中使用破折号("-)、小写字母([a-z])和数字([0-9])。没有下划线("_),也没有大写。为什么使它变得比必要的更复杂?更有争议的是,我也从来没有使用斜线("EDOCX1〔0]),因为它是一个有用的指示分支是"特殊的"。基本上没有理由使用"/"而不是"-",除了帮助自动折叠它们的哑GUI工具(如树),智能GUI可以/应该像在破折号"-"上一样轻松。
- 这是这个/^[./]...@[/.]的正则表达式$^@$[~^:x00-x20x7fs?*[&93;/g这将找到无效字符,这样您就可以用"-"或您想要的任何字符替换它们。
- 值得注意的是,&字符有时会导致Windows上的分支名称出现问题。
- @迈克尔一世第二个底线是:"为什么要使它变得比必要的更复杂?"这意味着简单地排除所有可能在任何机器或任何工具上造成麻烦的字符,或者换句话说,将自己限制在最低限度但足够的白名单中。
- 所以我可以叫git checkout -b mybranch.1.2?
- 我想知道分号是否不允许?,我们使用了分号,然后我使用git push--mirror将我们的存储库克隆到另一台服务器,并且每个带有分号的分支名称都失败。它使用了第一部分,下一部分试图作为命令执行:remote:fatal:不明确的参数"refs/heads/bug-199":未知修订或路径不在工作树中。远程:使用"--"将路径与修订分开,如:remote:'git[..]--[..]'远程:sh:querybuilder:找不到名为bug-199;querybuilder的分支的命令。