This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
library:git:generalcmd [2023/01/19 17:10] lhaosen [1.2 克隆一个带子模块的仓库] |
library:git:generalcmd [2023/02/16 17:13] (current) lhaosen [1.7 向下同步子模块仓库] |
||
---|---|---|---|
Line 280: | Line 280: | ||
指向主仓库记录子模块的路径 | 指向主仓库记录子模块的路径 | ||
gitdir: ../ | gitdir: ../ | ||
+ | |||
+ | |||
+ | ==== - 查看所有子模块 ==== | ||
+ | git submodule | ||
Line 292: | Line 296: | ||
* git submodule init git submodule update 两条指令可以合并为: | * git submodule init git submodule update 两条指令可以合并为: | ||
* git submodule init 的作用就是将子模块的信息写到 .git/ | * git submodule init 的作用就是将子模块的信息写到 .git/ | ||
- | * git submodule update 的作用是将子模块的空目录 clone 成对应版本的 git 仓库。当目录为空时,git submodule 显示的子模块不带版本信息。 | + | * git submodule update 的作用是将子模块的空目录 clone 成对应版本的 git 仓库。 |
+ | * 当目录为空时,git submodule 显示的子模块不带版本信息。 | ||
Line 303: | Line 308: | ||
- | ==== - 修改子模块 ==== | ||
- | ==== - 从已有的文件创建 git 子模块 ==== | ||
- | | + | ==== - 主仓库添加子模块(将已有的目录设为子模块)==== |
+ | |||
+ | | ||
git checkout v2.0 | git checkout v2.0 | ||
Line 328: | Line 333: | ||
git submodule add https:// | git submodule add https:// | ||
git commit -m "add submodule version 1.0" | git commit -m "add submodule version 1.0" | ||
+ | |||
+ | ==== - 删除子模块 ==== | ||
+ | * 逆初始化模块,其中{MOD_NAME}为模块目录,执行后可发现模块目录被清空 | ||
+ | |||
+ | git submodule deinit < | ||
+ | |||
+ | * 删除.gitmodules中记录的模块信息(--cached选项清除.git/ | ||
+ | |||
+ | git rm --cached < | ||
+ | |||
+ | * 提交更改到代码库,可观察到' | ||
+ | |||
+ | git commit -am " | ||
==== - 向下同步子模块仓库 ==== | ==== - 向下同步子模块仓库 ==== | ||
+ | git submodule init | ||
git submodule update | git submodule update | ||
- | | + | |
+ | 或 | ||
git submodule update --init --recursive | git submodule update --init --recursive | ||
| | ||
| | ||
- | ==== 查看所有子模块 ==== | ||
- | git submodule | ||