git submodule
git
用法
git submodule update --init --recursive把另一個儲存庫固定在某個提交上,嵌進你的儲存庫裡;普通複製後那個目錄是空的,要 update --init,而父儲存庫記住的是提交而不是分支。
常用選項
| 選項 | 含義 |
|---|---|
| add <url> <path> | pin another repository at a path |
| update --init | fill in a submodule folder that a clone left empty |
| --recursive | go into submodules of submodules |
| update --remote | move the pin to the tip of the tracked branch |
| status | the commit each submodule sits at |
| deinit <path> | unregister it |
| foreach <cmd> | run a command in each one |
範例
git submodule update --init --recursivethe command that fills empty submodule folders after a clone
git submodule add https://github.com/x/lib.git vendor/libadds a dependency as a submodule
git submodule update --remoteupdates the pinned commit to the branch tip
難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. git submodule 是做什麼的?
把另一個儲存庫固定在某個提交上,嵌進你的儲存庫裡;普通複製後那個目錄是空的,要 update --init,而父儲存庫記住的是提交而不是分支。
Q. 怎麼寫?
git submodule update --init --recursive —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 7 個,完整列表在 man git。這條命令屬於git。
相關命令
man 手冊: man git-submodule