git仓库支持submodule

概述

git仓库引用其他仓库,类似软连接

//used
git submodule add git://github.com/[USERNAME]/[REPO_NAME].git TARGET_FOLDER

在主仓库创建为TARGET_FOLDER的文件夹
这会克隆一个外部仓库: git://github.com/[USERNAME]/[REPO_NAME].git 到 TARGET_FOLDER,类似 git clone
这同时将自动生成一个.submodules目录

01、初始化仓库

all
test001
test002
test003

all仓库下
    test001  -> git仓库地址 test001
    test002  -> git仓库地址 test002
    test003  -> git仓库地址 test003

[email protected]:opt/all.git

[email protected]:opt/test001.git
[email protected]:opt/test002.git
[email protected]:opt/test003.git

02、使用submodule创建主仓库目录

git submodule add [email protected]:opt/test001.git test001
git submodule add [email protected]:opt/test002.git test002
git submodule add [email protected]:opt/test003.git test003

03、提交代码到git all仓库

git add .
git commit -m "UPDATE"
git push
git push -u origin master

git submodule 
git submodule status
git submodule update
git remote -v

04、在all仓库构建

//git clone时候需要加上--recursive,否则克隆下来的 TARGET_FOLDER是空文件夹
git clone --recursive [email protected]:opt/all.git

如果没加--recursive,克隆后只需要初始化子模块
git submodule update --init --recursive
posted @ 2023-06-03 10:43  mvpbang  阅读(204)  评论(0)    收藏  举报