git 组织git分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11051289/
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
Organizing git branches
提问by mgilson
I have a large-ish project that I'm working on which uses git as the VCS. At any given time I'm working on implementing a few features/bugfixes, etc. For any given feature/bug, It would be nice to create a hierarchy of branches -- e.g.
我有一个大型项目,我正在使用 git 作为 VCS。在任何给定的时间我都在努力实现一些功能/错误修复等。对于任何给定的功能/错误,创建一个分支层次结构会很好——例如
$ git branch
feature1
sub-branch1
sub-branch2
sub-branch3
feature2
sub-brancha
*sub-branchb #<--currently checked out
sub-branchc
bugfix1
sub-branch-foo
$ git checkout sub-brancha
$ git branch
feature1
sub-branch1
sub-branch2
sub-branch3
feature2
*sub-brancha #<--currently checked out
sub-branchb
sub-branchc
bugfix1
sub-branch-foo
Is it possible to do something like this, or do I need to adopt a more primitive naming scheme?
是否可以做这样的事情,还是我需要采用更原始的命名方案?
EDIT
编辑
To make it slightly more concrete what I'm looking for, if feature1 is a git branch, then in the example above, sub-branch1 would all have been created by git checkout -b sub-branch1
from the feature1
branch (which is branched from master). e.g.:
为了使它稍微具体是什么我要找的,如果特征1是一个Git分支,然后在上面,子BRANCH1将所有已被创建的示例git checkout -b sub-branch1
从feature1
分支(这是从主支)。例如:
$ git checkout master
$ git checkout -b feature1
$ git checkout -b testing
$ git branch
master
feature1
*testing
$ git checkout master
$ git checkout -b feature2
$ git branch
master
feature1
testing
*feature2
Having git branch simply organize branches by where they came from (with a little extra indentation) is probably good enough for my purposes ... Although super bonus points if I can have:
让 git branch 简单地根据分支的来源(带有一点额外的缩进)来组织分支,这对我的目的来说可能已经足够了……尽管如果我可以的话,可以获得超级加分:
$ git branch
feature1
testing
feature2
testing
bugfix1
sub-branch-foo
With some way to manage the name-conflict between "feature1/testing" and "feature2/testing"
通过某种方式来管理“feature1/testing”和“feature2/testing”之间的名称冲突
采纳答案by jgosmann
You can use a naming schemata like feature1/sub-brancha, feature2/sub-branchb and so on, the slash in the name is not a problem for git. However, the branches will still be handled as normal branches (but I wouldn't know how one could handle subbranches differently). The git branch command will list the branches of course with its full name and not the way it's in the example.
您可以使用命名模式,如 feature1/sub-branch、feature2/sub-branchb 等,名称中的斜杠对 git 来说不是问题。但是,分支仍将作为普通分支处理(但我不知道如何以不同方式处理子分支)。git branch 命令当然会用它的全名而不是它在示例中的方式列出分支。
Interestingly, the naming schemata including slashes will create a directory hierarchy in .git/refs/heads/. Maybe that's useful for handling the subbranches with some low level commands?
有趣的是,包含斜杠的命名模式将在 .git/refs/heads/ 中创建目录层次结构。也许这对于使用一些低级命令处理子分支很有用?
回答by migu
Branches in Git are in fact symbolic refs to a key in Git's object store. To quote the documentation ("What is a branch"):
Git 中的分支实际上是对 Git 对象存储中键的符号引用。引用文档(“什么是分支”):
When we need to be precise, we will use the word "branch" to mean a line of development, and "branch head" (or just "head") to mean a reference to the most recent commit on a branch. In the example above, the branch head named "A" is a pointer to one particular commit, but we refer to the line of three commits leading up to that point as all being part of "branch A".
当我们需要精确时,我们将使用“branch”这个词来表示一条开发线,“branch head”(或只是“head”)表示对分支上最近提交的引用。在上面的示例中,名为“A”的分支头是指向一个特定提交的指针,但我们将指向该点的三个提交的行称为“分支 A”的一部分。
Git manages only a list of references which are stored in files under .git/refs
. Those references are simply not designed as a tree-like structure.
Git 仅管理存储在.git/refs
. 这些引用根本没有设计为树状结构。
I recommend to use a branch naming scheme that conveys the hierarchy.
我建议使用传达层次结构的分支命名方案。
Another possibility is to write an extension that handles the branch tree for you.
另一种可能性是编写一个为您处理分支树的扩展。