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
    
  • 相关阅读:
    POJ1821 Fence 单调队列优化DP
    ZOJ 4114 dp
    2019 Multi-University Training Contest 2
    Fibonacci 矩阵乘法入门
    C
    258. Add Digits
    292. Nim Game
    345. Reverse Vowels of a String
    344. Reverse String
    169. Majority Element
  • 原文地址:https://www.cnblogs.com/stacks/p/7602337.html
Copyright © 2011-2022 走看看