我使用svn:externals从另一个SVN存储库中使用了两个SVN项目。
我怎样才能在Git中拥有相同的存储库布局结构?
Git有两种方法,但不完全等同于svn:externals:
-r
参数的svn:externals。子模块易于设置,但所有用户都必须管理子模块,子模块不会自动包含在结帐(或克隆)中。
尽管将更改提交回其他项目很容易,但如果更改了repo,这样做可能会导致问题。因此,将更改提交回正在开发的项目通常是不合适的。正如我在“Git submodule new version update”中提到的,您可以使用Git 1.8.2子模块实现相同的SVN外部功能:
git config -f .gitmodules submodule.<path>.branch <branch>
这足以使子模块跟随分支(如子模块upstream repo的远程分支的LATEST提交)。你需要做的就是:
git submodule update --remote
这将更新子模块。
更多细节见“git submodule
tracking latest”。
要将现有子模块转换为跟踪分支的一个子模块:请参阅“Git submodules: Specify a branch/tag”中的所有步骤。
我是gil (git links) tool的作者
我有一个替代解决方案 - gil (git links) tool
它允许描述和管理复杂的git存储库依赖项。
它还提供了git recursive submodules dependency problem的解决方案。
考虑您有以下项目依赖项:sample git repository dependency graph
然后,您可以使用存储库关系描述定义.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链接:
最后,您必须更新根示例存储库:
# 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"
Pull,push命令以类似的方式工作:
gil pull
gil push
Gil(git links)工具支持以下命令:
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