zoukankan      html  css  js  c++  java
  • git配置子模块

    使用场景

    有时候我们会遇到这样的需求,两个版本仓库A和B都是分离的,但是A仓库又依赖于B仓库,这种情况下我们就需要配置B仓库为A仓库的子模块,当拉取A仓库的时候B仓库也会跟随着被拉取下来,就是说把A仓库和B仓库当做类似一个项目来使用。

    配置方法

    1. 使用git的子模块来配置此方法,步骤:
    拉取A仓库:

    git clone .../A.git
    cd A
    git submodule add .../B.git    #在A仓库添加B仓库为子模块
    git status
    git add .    #重新提交A仓库
    git commit -m 'add submodule B.git'
    git push origin master
    

    2. 子模块发生变更之后push到远程仓库需要注意如下顺序:
    1. 首先在子模块中进行一次push
    2. 然后在主仓库进行一次push

    cd B
    echo "This is a submodule" > a.txt
    git add .
    git commit -m 'add a.txt'
    git push origin master
    cd ..
    git status
    git add .
    git commit 'update submodule B add a.txt'
    git push origin master
    

    3. 克隆带有子模块的仓库的两种方法:
    方法一:先克隆父项目,然后执行命令初始化和更新子项目

    git clone .../A.git
    cd A
    git submodule init
    git submodule update
    

    方法二:递归克隆

    git clone A.git --recursive
    
  • 相关阅读:
    web开发之mysql优化总结
    使用webpack构建属于你自己的npm包
    jwt在node中的应用与实践
    zookeeper启动失败解决办法(3.5.7)
    oracle表分区详解
    oracle job
    ORACLE恢复误删的表数据
    go mod使用 踏雪扬尘
    sparkcore 学习 踏雪扬尘
    GO语言基本知识 踏雪扬尘
  • 原文地址:https://www.cnblogs.com/stacks/p/7602337.html
Copyright © 2011-2022 走看看