问题描述
当我在Git中命名分支时,我总是倾向于以字母开头.例如mybranch89
.
When I name branches in Git, I always tend to start with a letter. mybranch89
for example.
是否有任何命名Git分支的规则?例如,我应该始终以字母开头,还是只能使用数字的分支名称,例如876
Are there any rules to naming Git branches? For example, should I always begin with a letter, or are number only branch names possible such as 876
推荐答案
规则为相当复杂,但是当您认为分支最终成为文件系统上的文件时,它们是有意义的:
The rules are rather complicated, but when you consider that branches end up as files on the filesystem, they make sense:
-
它们可以包含斜杠/用于层次结构(目录)分组,但是 斜杠分隔的组件不能以点开头.或以 顺序.lock.
They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.
它们必须至少包含一个/.这会强制存在 类别,例如heads/,tags/等,但实际名称不是 受限制的.如果使用--allow-onelevel选项,则此规则为 放弃.
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.
它们不能具有ASCII控制字符(即其值的字节 小于\ 040或\ 177 DEL),空格,代字号〜,插入号^或冒号 :任何地方.
They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.
他们不能带有问号?,星号*或方括号[ 任何地方.请参阅下面的--refspec-pattern选项以获取以下内容的例外情况 这条规则.
They cannot have question-mark ?, asterisk *, or open bracket [ anywhere. See the --refspec-pattern option below for an exception to this rule.
它们不能以斜杠开头或结尾/不能包含多个 连续的斜杠(请参阅下面的--normalize选项以获取 此规则的例外)
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 @.
它们不能包含\.
请注意,这是为引用命名,而不是分支.分支是类似于refs/heads/<branchname>
的引用.
Note that this is for naming of references, not branches. A branch is a reference that looks like refs/heads/<branchname>
.
这篇关于命名Git分支的规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!