组织git分支

mgi*_*son 19 git branch

我正在开发一个使用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
Run Code Online (Sandbox Code Playgroud)

有可能做这样的事情,还是我需要采用更原始的命名方案?

编辑

为了使它稍微具体是什么我要找的,如果特征1是一个Git分支,然后在上面的例子中,子BRANCH1将所有已创建git checkout -b sub-branch1feature1分支(这是从主支).例如:

$ 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
Run Code Online (Sandbox Code Playgroud)

有git分支只是根据他们来自哪里组织分支(有一点额外的缩进)可能足够我的目的...虽然我可以有超级奖励积分:

$ git branch
  feature1
       testing
  feature2
       testing
  bugfix1
       sub-branch-foo
Run Code Online (Sandbox Code Playgroud)

用某种方法来管理"feature1/testing"和"feature2/testing"之间的名称冲突

jgo*_*ann 17

您可以使用命名模式,如feature1/sub-brancha,feature2/sub-branchb等,名称中的斜杠对git来说不是问题.但是,分支仍将作为普通分支处理(但我不知道如何以不同方式处理子分支).git branch命令将列出当然具有全名的分支,而不是示例中的分支.

有趣的是,包含斜杠的命名模式将在.git/refs/heads /中创建目录层次结构.也许这对于使用一些低级命令处理子分支很有用?

  • 您可以编写一个小工具来强制执行命名方案.也许一些别名已经足够了.或者你可以看一下[gitflow](https://github.com/nvie/gitflow),它有点朝这个方向发展(但可能并不完全是你需要的). (3认同)
  • 另外值得一提的是,当你用这种方式命名时,某些GUI客户端如[Tower](http://www.git-tower.com)组分支(即`feature/sub-branch1`和`feature/sub-branch2 `成为`sub-branch1`和`sub-branch2`分组在`feature`下面. (3认同)
  • 虽然这是一个很好的策略,但有一点需要记住。如果您创建名为 feature1 的分支,则无法创建名为 feature1/sub1 的分支。所以你必须创建feature1/main,然后才能创建feature1/sub1。因此,如果您想在 feature1 分支下工作或将工作集成到其中。 (2认同)