2013-11-14 46 views
14

我正在尝试使用git子模块将10个以上的存储库聚合到一个结构中以便于开发。Git子模块来跟踪远程分支

它应该克隆模块并签出一个分支。 取而代之的是,模块在分离头模式下检出。

git clone [email protected]:org/global-repository.git 
git submodule update —init 
cd config-framework 
git status 

$git status 
#HEAD detached at b932ab5 
nothing to commit, working directory clean 

gitmodules文件似乎是好的

$cat .gitmodules 
[submodule "config-framework"] 
     path = config-framework 
     url = [email protected]:org/config-framework.git 
     branch = MY_BRANCH 

我们希望被默认选中的MY_BRANCH分支出来的,而不是分离的头。 我们如何实现这一目标?

+0

这是子模块的工作方式。主项目引用特定的提交,而不是分支。 – twalberg

回答

18

子模块总是detached HEAD mode签出。

这是因为子模块会检出存储在special entry in the index of the parent repo中的SHA1。

另外,如果你想有一个子模块跟着你已经在.gitmodules注册的分支,你需要:

git submodule update --init --remote 

--remote会让git fetch,再加上新HEAD的结帐。
唉,即使签出将是一个提交,而不是分支(因为您在子模块中默认没有本地分支),所以...回到分离的HEAD模式。
查看更多“Git submodules: Specify a branch/tag”。

你可以试试(未测试)一:

git submodule foreach 'git checkout -b $(git config -f /path/to/parent/repo/.gitmodules --get submodule.$path.branch)' 

我拿的事实git submodule foreach先后获得“$path”的优势,相对于上层项目子模块目录的名称。


有指定分行一个子模块是自动签出(commit 23d25e4 GIT中2.0)企图....但它得到了逆转(commit d851ffb,四月2D 2014)!
它可能会很快出现,但目前尚未实现。

+0

希望能在这里回答我的相关问题:http://stackoverflow.com/q/25799319/2872891。谢谢! –

1

如果您的计划是对子模块做出贡献,最好的方法是将其单独检查为常规git回购。你在不同的遥控器分支机构工作吗?然后将您的子模块指向想要用于测试的单个远程。