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