2012-03-26 60 views
9

是相對的子模塊小白,我想從它的起源與更新我的子模塊,並做:我的git子模塊的狀態如何,我該如何清理它?

git pull 

這導致:

remote: Counting objects: 111, done. 
remote: Compressing objects: 100% (3/3), done. 
remote: Total 57 (delta 54), reused 57 (delta 54) 
Unpacking objects: 100% (57/57), done. 
From github.com:eteanga/smarty 
    8e9a011..818ab3e master  -> origin/master 
You are not currently on a branch, so I cannot use any 
'branch.<branchname>.merge' in your configuration file. 
Please specify which remote branch you want to use on the command 
line and try again (e.g. 'git pull <repository> <refspec>'). 
See git-pull(1) for details. 

試圖修復:

git pull origin master 

輸出:

From github.com:eteanga/smarty 
* branch   master  -> FETCH_HEAD 
Updating 8e9a011..818ab3e 
Fast-forward 
[snip] 

現在看來我確實得到了更新的代碼,,但我目前沒有在任何分支上工作。

我該怎麼做才能正確更新我的子模塊,以及我應該如何解決這個當前狀態?

回答

16

git submodule update之後,子模塊中的HEAD被設置爲保存在超級項目中的子模塊提交散列值。如果你想在HEAD重置輔助模塊跟蹤origin/master新提交你首先要結帳到master,然後拉變化:

在子模塊目錄:

git checkout master 
git pull origin master 
+0

感謝好心,說似乎工作。我是否必須在每臺機器上執行此更新以檢查此主回購庫,以便讓他們獲取最新的子模塊代碼? – eoinoc 2012-03-26 18:19:49

+0

我遇到了同樣的問題,看起來您必須爲每個簽出的回購庫中的每個子模塊執行此操作。我想找到一個解決方案,我可以使用'git clone --recursive'克隆主repo,然後根據需要推送和更改每個子模塊的更改。有人知道怎麼做嗎? – Simon 2012-10-17 11:46:15

+2

**只是打我**:在'git submodule foreach '*似乎*做竅門後在上面的答案中運行這兩個命令。不確定任何潛在的副作用,雖然... – Simon 2012-10-17 11:56:02