我可以提供另一种解决方案(git子模块的替代方案)来解决你的问题 - gil (git links) 工具
它允许描述和管理复杂的 git 仓库依赖关系。
此外,它还提供了解决git递归子模块依赖问题的解决方案。
考虑下面这个项目的依赖关系图:
样例 git 仓库依赖关系图
然后你就可以定义一个.gitlinks
文件来描述仓库之间的关系:
# Projects
CppBenchmark CppBenchmark https://github.com/chronoxor/CppBenchmark.git master
CppCommon CppCommon https://github.com/chronoxor/CppCommon.git master
CppLogging CppLogging https://github.com/chronoxor/CppLogging.git master
# Modules
Catch2 modules/Catch2 https://github.com/catchorg/Catch2.git master
cpp-optparse modules/cpp-optparse https://github.com/weisslj/cpp-optparse.git master
fmt modules/fmt https://github.com/fmtlib/fmt.git master
HdrHistogram modules/HdrHistogram https://github.com/HdrHistogram/HdrHistogram_c.git master
zlib modules/zlib https://github.com/madler/zlib.git master
# Scripts
build scripts/build https://github.com/chronoxor/CppBuildScripts.git master
cmake scripts/cmake https://github.com/chronoxor/CppCMakeScripts.git master
每一行都以以下格式描述git链接:
- 仓库的唯一名称
- 仓库相对路径(从.gitlinks文件所在路径开始)
- Git 仓库将在 git clone 命令中使用
要检出的仓库分支
- 空行或以#开头的行不会被解析(视为注释)。
最后,您需要更新您的根示例库:
# Clone and link all git links dependencies from .gitlinks file
gil clone
gil link
# The same result with a single command
gil update
作为结果,您将克隆所有必需的项目,并以适当的方式将它们链接在一起。
如果您想将某个仓库中的所有更改与子链接仓库中的所有更改一起提交,可以使用一个命令完成:
gil commit -a -m "Some big update"
拉取和推送命令的工作方式类似:
gil pull
gil push
Gil(git链接)工具支持以下命令:
usage: gil command arguments
Supported commands:
help - show this help
context - command will show the current git link context of the current directory
clone - clone all repositories that are missed in the current context
link - link all repositories that are missed in the current context
update - clone and link in a single operation
pull - pull all repositories in the current directory
push - push all repositories in the current directory
commit - commit all repositories in the current directory
了解更多关于Git 递归子模块依赖问题的信息。