2016/04/07

Just a Note:Git Submodule

紀錄 git submodule 多人共用的情境與步驟。

1. 第一個新增 submodule 的人
git submodule add -b [submodule_branch] [submodule_url] [submodule_folder] (submodule_folder 需不存在,會產生或更新 .gitmodules)
git submodule init (register submodule in git)
git submodule update (把 submodule 的檔案更新回來)
git add .
git commit -m "add submodule"
git push

2. 其他人
git pull (submodule 目錄會是空的)
git submodule init (register submodule in git)
git submodule update (把 submodule 的檔案更新回來)

3. 更新 submodule:
(1) 在 submodule 原始的 repository (不是在此系統的 repo 下)修改,按照標準 git 程序進行更新。
(2) 直接在此系統的 submodule 目錄下進行修改:
cd [submodule_folder]
git add [stuff]
git commit -m "[comment]"
git push origin HEAD:[submodule_branch]

4. submodule 有更新,第一個處理 submodule 更新的人
git submodule update --remote (更新 submodule 檔案及 local git 紀錄的 submodule hash)
git add .
git commit -m "submodule update"
git push (如此 remote server 的 submodule reference 才會更新,否則其他人都還是會用到舊版的 submodule)

5. 其他人
git pull
git submodule update


參考:
Git submodules: Specify a branch/tag
http://stackoverflow.com/questions/1777854/git-submodules-specify-a-branch-tag
Git Submodule 的認識與正確使用!
http://josephjiang.com/entry.php?id=342
Issue with adding common code as git submodule: “already exists in the index”
http://stackoverflow.com/questions/12898278/issue-with-adding-common-code-as-git-submodule-already-exists-in-the-index
How do I remove a Git submodule?
http://stackoverflow.com/questions/1260748/how-do-i-remove-a-git-submodule
git submodule update --remote vs git pull
http://stackoverflow.com/questions/19619747/git-submodule-update-remote-vs-git-pull
git-submodule(1) Manual Page
http://git-scm.com/docs/git-submodule