Git 子模块

git submodule -h

本地设置子模块并上传远程GIT仓库

git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
git diff --cached :: 确定修改
git commit  :: ---(写描述)commit .gitmodules
git push    :: push commit to remote
  • -b <branch>  specify sync which submodule branch 
  • --name <name> submdoule name ,default is  path

注意:子模块仓库填的URL是SSH还是HTTPS,推荐使用SSH方式连接GIT,避免密码修改需要重新填写HTTPS

例:添加子模块到仓库,配置拉取时拉分支为Alpha的子模块。子目录本地路径:<repoRoot>/script/pipe 

git submodule add -b Alpha git@gitlab.XXXXXX.com:data/test_git_runner.git script/pipe

子模块拉取

::递归拉取所有子模块及其子模块的子模块
git clone <repo> --recurse-submodules
 
::只拉取当前仓库的子模块
git submodule init
git submodule update
 
::递归拉取所有子模块及其子模块的子模块
git submodule update --init --recursive

删除本地子模块以重新拉取子模块

rmdir /s /q <submodulDir>
rmdir /s /q <RepoDir/.git/modules>

设置子模块的分支(Git Version >=1.82)

git config -f .gitmodules submodule.<subModuleName>.branch <branch>
git submodule update --remote
git status :: .gitmodules 被修改了
git add .gitmodules
git commit
git push
posted @ 2023-02-21 16:41  Stranger115  阅读(41)  评论(0编辑  收藏  举报