​git submodule添加、更新和删除​

添加

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

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

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

git submodule add -b <branch> <url> <path> 

例子

未指定分支

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 init git 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 子模块目录

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值