GIT-子模块

来源:互联网 发布:微信小程序服务器php 编辑:程序博客网 时间:2024/05/16 14:11

动机

公司有若干个项目,并且各个项目有关联(代码层次),这时我们需要抽取出一个公共模块供其它项目使用,这时我们就需要使用submodule(子模块)

使用步骤

  • 进入项目目录(.git 目录)
  • 使用命令添加子模块

    • git submodule add git@git.xxxxxx.com:app-labs/swift-mkit.git swift-mkit
    • 这时会 clone 子模块,并且生成两个文件,如图:
      git_submodule_add_status.png
  • .gitmodules中包含子模块的详细信息

clone 包含子模块的项目

方式一:递归 clone 完整的项目

  • git clone --recursive https://git.coding.net/chernyog/XXX.git

方式二:先 clone 父项目,再更新子项目

  • clone 父项目
    • git clone https://git.coding.net/chernyog/XXX.git
    • 此时子模块也会出现,只是空目录而已!
  • 初始化子模块
    • git submodule init
  • 更新子模块
    • git submodule update
  • 注意:必须先初始化子模块,否则报错!
    git_submodule_update_error.png
原创粉丝点击