git submodule添加、更新和删除
发布日期:2021-05-09 04:08:31 浏览次数:22 分类:博客文章

本文共 1094 字,大约阅读时间需要 3 分钟。

添加

git submodule add 
  • url:替换为自己要引入的子模块仓库地址
  • path:要存放的本地路径

执行添加命令成功后,可以在当前路径中看到一个.gitsubmodule文件,里面的内容就是我们刚刚add的内容

如果在添加子模块的时候想要指定分支,可以利用 -b 参数

git submodule add -b 

例子

未指定分支

git submodule add https://github.com/tensorflow/benchmarks.git 3rdparty/benchmarks

.gitsubmodule内容

[submodule "3rdparty/benchmarks"]	path = 3rdparty/benchmarks	url = https://github.com/tensorflow/benchmarks.git

指定分支

git submodule add -b cnn_tf_v1.10_compatible https://github.com/tensorflow/benchmarks.git 3rdparty/benchmarks

.gitsubmodule内容

[submodule "3rdparty/benchmarks"]	path = 3rdparty/benchmarks	url = https://github.com/tensorflow/benchmarks.git	branch = cnn_tf_v1.10_compatible

使用

当我们add子模块之后,会发现文件夹下没有任何内容。这个时候我们需要再执行下面的指令添加源码。

git submodule update --init --recursive

这个命令是下面两条命令的合并版本

git submodule initgit submodule update

更新

我们引入了别人的仓库之后,如果该仓库作者进行了更新,我们需要手动进行更新。即进入子模块后,执行

git pull

进行更新。

删除

  1. 删除子模块目录及源码
rm -rf 子模块目录
  1. 删除.gitmodules中的对应子模块内容
vi .gitmodules
  1. 删除.git/config配置中的对应子模块内容
vi .git/config
  1. 删除.git/modules/下对应子模块目录
rm -rf .git/modules/子模块目录
  1. 删除git索引中的对应子模块
git rm --cached 子模块目录
上一篇:Linux多cuda版本切换
下一篇:Linux CGroup入门

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月07日 12时08分19秒