Thursday, February 20, 2014

git submodule update 後, 不會自動對到master branch 的解法

git submodule update 後, 每次都在要commit 時被提醒沒有設branch, 這很怪, 查了一下才注意到root 在記錄submodule 的狀態只記錄最後commit 的hash id, 並沒有記錄是那個branch 的, 所以當你submodule update 會將hash id update後, branch 就拖勾了.

不過在git 1.8.1 之後加入了可以設定submodule 的branch 了, 使用方式是在加入submodule 時下-b 的參數

  git submodule add -b master [URL to Git repo];

這樣當我們 submodule update 時就會自動將branch 設為master , 這樣也比較像svn 的external link 的方式, 可以設定某個root 的git 使用某個submodule 的branch

不過如果現有的submodule 要加入呢?

 這時只要回到parent 的git 目錄去設定就可以了

git config -f .gitmodules submodule..branch  


參考連結:
ref1: integrate with the tip of the remote branch
ref2: if you have an existing submodule which isn't tracking a branch yet

No comments: