SVN:外部相当于Git?

dsi*_*ard 167 svn git

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

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

Pau*_*aul 131

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

  • Subtree merges insert the external project's code into a separate sub-directory within your repo. This has a detailed process to set up and then is very easy for other users, because it is automatically included when the repository is checked out or cloned. This can be a convenient way to include a dependency in your project.
    It is easy to pull changes from the other project, but complicated to submit changes back. And if the other project have to merge from your code, the project histories get merged and the two projects effectively become one.

  • Git子模块(手动)链接到另一个项目的存储库中的特定提交,就像带有-r参数的svn:externals一样.子模块易于设置,但所有用户都必须管理子模块,子模块不会自动包含在结帐(或克隆)中.
    尽管将更改提交回其他项目很容易,但如果更改了回购,这样做可能会导致问题.因此,将更改提交回正在开发的项目通常是不合适的.

  • 仅供参考,现在可以用svn:externals指定具体的修订版本(我相信1.5或1.6)? (17认同)
  • 仅供参考,git子模块可以自动管理和提交.git创建一个.gitmodules文件,可以/应该像.gitignore文件一样提交.有关详细信息,请参阅[http://git-scm.com/book/en/Git-Tools-Submodules]. (6认同)
  • @NateParsons始终可以使用`svn:externals`指定确切的修订号.对于修订版1.5,语法已更改为更灵活的格式.添加的是相对URL寻址. (5认同)
  • 我认为不可能像 svn:externals 那样 git 子模块单个文件 (3认同)

Von*_*onC 35

正如我在" Git子模块新版本更新 "中提到的,您可以使用Git 1.8.2子模块实现相同的SVN外部功能:

git config -f .gitmodules submodule.<path>.branch <branch>
Run Code Online (Sandbox Code Playgroud)

这足以使子模块跟随分支(如子模块上游repo的远程分支的LATEST提交).你需要做的就是:

git submodule update --remote
Run Code Online (Sandbox Code Playgroud)

这将更新子模块.

更多细节在" git submodule追踪最新 ".

要将现有子模块转换为跟踪分支的一个子模块:请参阅" Git子模块:指定分支/标记 "中的所有步骤.


chr*_*xor 5

我是gil (git links) 工具的作者

我有这个问题的替代解决方案 - gil (git links) 工具

它允许描述和管理复杂的 git 存储库依赖项。

它还为git recursive submodules 依赖问题提供了解决方案。

考虑您有以下项目依赖项: 示例 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
Run Code Online (Sandbox Code Playgroud)

每行以以下格式描述 git link:

  1. 存储库的唯一名称
  2. 仓库相对路径(从.gitlinks文件路径开始)
  3. 将在 git clone 命令中使用的 Git 存储库分支以结帐
  4. 不解析空行或以 # 开头的行(视为注释)。

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

# Clone and link all git links dependencies from .gitlinks file
gil clone
gil link

# The same result with a single command
gil update
Run Code Online (Sandbox Code Playgroud)

因此,您将克隆所有必需的项目并以适当的方式将它们相互链接。

如果您想提交某个存储库中的所有更改以及子链接存储库中的所有更改,您可以使用单个命令来完成:

gil commit -a -m "Some big update"
Run Code Online (Sandbox Code Playgroud)

拉、推命令的工作方式类似:

gil pull
gil push
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

更多关于git recursive submodules 依赖问题

  • 您应该在帖子顶部放置一个免责声明,说明您是 `gil` 的作者。 (3认同)