git submodule添加、更新和删除
1 2
| git submodule add <url> <path>
|
- url:替换为自己要引入的子模块仓库地址
- path:要存放的本地路径
执行添加命令成功后,可以在当前路径中看到一个.gitsubmodule文件,里面的内容就是我们刚刚add的内容
如果在添加子模块的时候想要指定分支,可以利用 -b 参数
1 2
| git submodule add -b <branch> <url> <path>
|
未指定分支#
1 2
| git submodule add https://github.com/tensorflow/benchmarks.git 3rdparty/benchmarks
|
.gitsubmodule内容
1 2 3 4
| [submodule "3rdparty/benchmarks"] path = 3rdparty/benchmarks url = https://github.com/tensorflow/benchmarks.git
|
指定分支#
1 2
| git submodule add -b cnn_tf_v1.10_compatible https:
|
.gitsubmodule内容
1 2 3 4 5
| [submodule "3rdparty/benchmarks"] path = 3rdparty/benchmarks url = https://github.com/tensorflow/benchmarks.git branch = cnn_tf_v1.10_compatible
|
当我们add子模块之后,会发现文件夹下没有任何内容。这个时候我们需要再执行下面的指令添加源码。
这个命令是下面两条命令的合并版本
1 2 3
| git submodule init git submodule update
|
我们引入了别人的仓库之后,如果该仓库作者进行了更新,我们需要手动进行更新。即进入子模块后,执行
进行更新。
- 删除子模块目录及源码
- 删除.gitmodules中的对应子模块内容
- 删除.git/config配置中的对应子模块内容
- 删除.git/modules/下对应子模块目录
1 2
| rm -rf .git/modules/子模块目录
|
- 删除git索引中的对应子模块