Here are some branch naming conventions that I use and the reasons for them
(以下是我使用的一些分支命名约定及其原因)
Branch naming conventions
(分支命名约定)
- Use grouping tokens (words) at the beginning of your branch names.
(在分支名称的开头使用分组令牌(单词)。)
- Define and use short lead tokens to differentiate branches in a way that is meaningful to your workflow.
(定义和使用短引导令牌,以对您的工作流程有意义的方式区分分支。)
- Use slashes to separate parts of your branch names.
(使用斜杠分隔部分名称。)
- Do not use bare numbers as leading parts.
(不要使用裸号作为主要部分。)
- Avoid long descriptive names for long-lived branches.
(避免长寿命分支的长描述性名称。)
Group tokens
(集团代币)
Use "grouping" tokens in front of your branch names.
(在分支名称前面使用“分组”标记。)
group1/foo
group2/foo
group1/bar
group2/bar
group3/bar
group1/baz
The groups can be named whatever you like to match your workflow.
(这些组可以根据您的工作流程命名。)
I like to use short nouns for mine. (我喜欢用我的短名词。)
Read on for more clarity. (继续阅读以获得更清晰。)
Short well-defined tokens
(短的定义明确的令牌)
Choose short tokens so they do not add too much noise to every one of your branch names.
(选择短标记,这样它们就不会为每个分支名称添加太多噪音。)
I use these: (我用这些:)
wip Works in progress; stuff I know won't be finished soon
feat Feature I'm adding or expanding
bug Bug fix or experiment
junk Throwaway branch created to experiment
Each of these tokens can be used to tell you to which part of your workflow each branch belongs.
(这些令牌中的每一个都可用于告诉您每个分支属于哪个工作流程部分。)
It sounds like you have multiple branches for different cycles of a change.
(听起来你有多个分支用于不同的变化周期。)
I do not know what your cycles are, but let's assume they are 'new', 'testing' and 'verified'. (我不知道你的周期是什么,但我们假设他们是'新','测试'和'验证'。)
You can name your branches with abbreviated versions of these tags, always spelled the same way, to both group them and to remind you which stage you're in. (您可以使用这些标签的缩写版本命名您的分支,总是以相同的方式拼写,以便对它们进行分组并提醒您所处的阶段。)
new/frabnotz
new/foo
new/bar
test/foo
test/frabnotz
ver/foo
You can quickly tell which branches have reached each different stage, and you can group them together easily using Git's pattern matching options.
(您可以快速判断哪些分支到达了不同的阶段,您可以使用Git的模式匹配选项轻松地将它们组合在一起。)
$ git branch --list "test/*"
test/foo
test/frabnotz
$ git branch --list "*/foo"
new/foo
test/foo
ver/foo
$ gitk --branches="*/foo"
Use slashes to separate parts
(使用斜杠分隔零件)
You may use most any delimiter you like in branch names, but I find slashes to be the most flexible.
(您可以在分支名称中使用大多数您喜欢的分隔符,但我发现斜杠是最灵活的。)
You might prefer to use dashes or dots. (您可能更喜欢使用破折号或圆点。)
But slashes let you do some branch renaming when pushing or fetching to/from a remote. (但是,当推送或从远程数据取出时,斜杠允许您进行一些分支重命名。)
$ git push origin 'refs/heads/feature/*:refs/heads/phord/feat/*'
$ git push origin 'refs/heads/bug/*:refs/heads/review/bugfix/*'
For me, slashes also work better for tab expansion (command completion) in my shell.
(对我来说,斜杠也可以更好地用于我的shell中的选项卡扩展(命令完成)。)
The way I have it configured I can search for branches with different sub-parts by typing the first characters of the part and pressing the TAB key. (我配置它的方式我可以通过键入部件的第一个字符并按TAB键来搜索具有不同子部件的分支。)
Zsh then gives me a list of branches which match the part of the token I have typed. (Zsh然后给我一个分支列表,它与我输入的令牌部分相匹配。)
This works for preceding tokens as well as embedded ones. (这适用于前面的令牌以及嵌入的令牌。)
$ git checkout new<TAB>
Menu: new/frabnotz new/foo new/bar
$ git checkout foo<TAB>
Menu: new/foo test/foo ver/foo
(Zshell is very configurable about command completion and I could also configure it to handle dashes, underscores or dots the same way. But I choose not to.)
((Zshell关于命令完成是非常可配置的,我也可以将它配置为以相同的方式处理破折号,下划线或点。但我选择不这样做。))
It also lets you search for branches in many git commands, like this:
(它还允许您在许多git命令中搜索分支,如下所示:)
git branch --list "feature/*"
git log --graph --oneline --decorate --branches="feature/*"
gitk --branches="feature/*"
Caveat: As Slipp points out in the comments, slashes can cause problems.
(警告:正如Slipp在评论中指出的那样,斜线可能会导致问题。)
Because branches are implemented as paths, you cannot have a branch named "foo" and another branch named "foo/bar". (因为分支是作为路径实现的,所以不能有名为“foo”的分支和名为“foo / bar”的另一个分支。)
This can be confusing for new users. (这可能会让新用户感到困惑。)
Do not use bare numbers
(不要使用裸号码)
Do not use use bare numbers (or hex numbers) as part of your branch naming scheme.
(不要使用裸号(或十六进制数)作为分支命名方案的一部分。)
Inside tab-expansion of a reference name, git may decide that a number is part of a sha-1 instead of a branch name. (在引用名称的制表符扩展内,git可以决定数字是sha-1的一部分而不是分支名称。)
For example, my issue tracker names bugs with decimal numbers. (例如,我的问题跟踪器使用十进制数字命名错误。)
I name my related branches CRnnnnn rather than just nnnnn to avoid confusion. (我将我的相关分支命名为CRnnnn而不仅仅是nnnnn以避免混淆。)
$ git checkout CR15032<TAB>
Menu: fix/CR15032 test/CR15032
If I tried to expand just 15032, git would be unsure whether I wanted to search SHA-1's or branch names, and my choices would be somewhat limited.
(如果我试图扩展15032,git将不确定我是否想要搜索SHA-1或分支名称,我的选择会有所限制。)
Avoid long descriptive names
(避免使用长描述性名称)
Long branch names can be very helpful when you are looking at a list of branches.
(当您查看分支列表时,长分支名称可能非常有用。)
But it can get in the way when looking at decorated one-line logs as the branch names can eat up most of the single line and abbreviate the visible part of the log. (但是,当查看装饰的单行日志时,它可能会妨碍,因为分支名称可能占用大部分单行并缩短日志的可见部分。)
On the other hand long branch names can be more helpful in "merge commits" if you do not habitually rewrite them by hand.
(另一方面,如果您不习惯性地手动重写,则长分支名称在“合并提交”中会更有帮助。)
The default merge commit message is Merge branch 'branch-name'
. (默认的合并提交消息是Merge branch 'branch-name'
。)
You may find it more helpful to have merge messages show up as Merge branch 'fix/CR15032/crash-when-unformatted-disk-inserted'
instead of just Merge branch 'fix/CR15032'
. (您可能会发现将合并消息显示为Merge branch 'fix/CR15032/crash-when-unformatted-disk-inserted'
而不仅仅是Merge branch 'fix/CR15032'
。)