zoukankan      html  css  js  c++  java
  • 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 子模块目录
    
    (。・∀・)ノ干杯
  • 相关阅读:
    免费的编程中文书籍索引【转】
    Linux字符集的查看及修改【转】
    expect学习笔记及实例详解【转】
    mycat学习笔记
    Vue-loader 开启压缩后的一些坑
    使用webpack搭建vue开发环境
    基于webpack和vue.js搭建开发环境
    Sublime Text 3 常用插件以及安装方法(vue 插件)
    NodeJS、NPM安装配置步骤(windows版本)
    Https方式使用Git@OSC设置密码的方式
  • 原文地址:https://www.cnblogs.com/jyroy/p/14367776.html
Copyright © 2011-2022 走看看