git submodule子模块

使用submodule有助于项目模块划分,提高git管理的性能。

demo
|-- .git/
|-- .gitignore
|-- lib
|-- README

添加子模块

注意需要在保存子模块的目录lib下执行

git submodule add git@192.168.0.190:root/module_x.git

查看缓冲区Index变化

git status

        new file:   .gitmodules
        new file:   lib/module_x

首先应当注意到新的 .gitmodules 文件。 该置文件保存了项目 URL 与已经拉取的本地目录之间的映射:

cat .gitmodules
[submodule "lib/module_x"]
        path = lib/module_x
        url = git@192.168.0.190:root/module_x.git

更新子模块

#更新带有submodule的项目
git submodule update --remote
Submodule path 'lib/module_y': checked out '65441273ea8d226bb5390e83e8ca76e78807
3f68'
#在主项目中提交子模块更新
git commit -a -m "update module_y"
#如果你的 submodule 又依赖了 submodule
git submodule foreach git submodule update

克隆含有子模块的项目

接下来我们将会克隆一个含有子模块的项目。 当你在克隆这样的项目时,默认会包含该子模块目录,但其中还没有任何文件:

git clone git@192.168.0.190:root/demo.git

你必须运行两个命令:git submodule init 用来初始化本地配置文件,而 git submodule update 则从该项目中抓取所有数据并检出父项目中列出的合适的提交。

git submodule init
git submodule update

不过还有更简单一点的方式。 如果给 git clone 命令传递 –recursive 选项,它就会自动初始化并更新仓库中的每一个子模块。

git clone --recursive git@192.168.0.190:root/demo.git

参照:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值