2013-11-14 61 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回購。你在不同的遙控器分支機構工作嗎?然後將您的子模塊指向想要用於測試的單個遠程。