SVN:外部相当于Git?

问题描述 投票:166回答:3

我使用svn:externals从另一个SVN存储库中使用了两个SVN项目。

我怎样才能在Git中拥有相同的存储库布局结构?

svn git
3个回答
130
投票

Git有两种方法,但不完全等同于svn:externals:

  • 子树合并将外部项目的代码插入到repo中的单独子目录中。这有一个detailed process to set up然后对其他用户来说非常容易,因为在检出或克隆存储库时会自动包含它。这可以是在项目中包含依赖项的便捷方式。 从其他项目中提取更改很容易,但提交更改很复杂。如果另一个项目必须从您的代码合并,项目历史将合并,两个项目实际上成为一个。
  • Git submodulesmanual)链接到另一个项目的存储库中的特定提交,非常类似于带有-r参数的svn:externals。子模块易于设置,但所有用户都必须管理子模块,子模块不会自动包含在结帐(或克隆)中。 尽管将更改提交回其他项目很容易,但如果更改了repo,这样做可能会导致问题。因此,将更改提交回正在开发的项目通常是不合适的。

35
投票

正如我在“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”中的所有步骤。


0
投票

我是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链接:

  1. 存储库的唯一名称
  2. 存储库的相对路径(从.gitlinks文件的路径开始)
  3. Git仓库将用于git clone命令Repository branch to checkout
  4. 以#开头的空行或行未被解析(视为注释)。

最后,您必须更新根示例存储库:

# 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

关于git recursive submodules dependency problem的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.