SVN:外部等效于 Git?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/571232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SVN:externals equivalent in Git?
提问by dsimard
I have two SVN projects in use from another SVN repository using svn:externals.
我使用svn:externals从另一个 SVN 存储库中使用了两个 SVN 项目。
How can I have the same repository layout structure in Git?
如何在 Git 中拥有相同的存储库布局结构?
采纳答案by Paul
Git has two approaches similar to, but not exactly equivalent to svn:externals:
Git 有两种类似于但不完全等同于 svn:externals 的方法:
Subtree mergesinsert the external project's code into a separate sub-directory within your repo. This has a detailed process to set upand 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 submodules(manual) link to a particular commit in another project's repository, much like svn:externals with an
-r
argument. Submodules are easy to set up, but all users have to manage the submodules, which are not automatically included in checkouts (or clones).
Although it is easy to submit changes back to the other project, doing so may cause problems if the repo has changed. Therefore it is generally not appropriate to submit changes back to a project that is under active development.
子树合并将外部项目的代码插入到您的 repo 中的单独子目录中。这有一个详细的设置过程,然后对于其他用户来说非常容易,因为它会在检出或克隆存储库时自动包含在内。这是在项目中包含依赖项的便捷方式。
从另一个项目中提取更改很容易,但提交更改很复杂。如果另一个项目必须从您的代码中合并,项目历史就会合并,两个项目实际上合二为一。Git 子模块(手动)链接到另一个项目存储库中的特定提交,很像带有
-r
参数的svn:externals。子模块易于设置,但所有用户都必须管理子模块,这些子模块不会自动包含在检出(或克隆)中。
尽管将更改提交回另一个项目很容易,但如果 repo 发生更改,这样做可能会导致问题。因此,将更改提交回正在积极开发的项目通常是不合适的。
回答by VonC
As I mention in "Git submodule new version update", you can achieve the same SVN external featurewith Git 1.8.2 submodules:
正如我在“ Git 子模块新版本更新”中提到的,您可以使用 Git 1.8.2 子模块实现相同的 SVN 外部功能:
git config -f .gitmodules submodule.<path>.branch <branch>
This is enough for a submodule to follow a branch (as in the LATEST commit of a remote branch of a submodule upstream repo). All you need to do is a:
这足以让子模块跟随一个分支(如在子模块上游 repo的远程分支的最新提交中)。您需要做的就是:
git submodule update --remote
That will update the submodule.
这将更新子模块。
More details are in "git submodule
tracking latest".
更多细节在“git submodule
追踪最新”中。
To convert an existing submodule into one tracking a branch: see all the steps in "Git submodules: Specify a branch/tag".
要将现有子模块转换为跟踪分支的子模块:请参阅“ Git 子模块:指定分支/标签”中的所有步骤。
回答by chronoxor
I'm the author of gil (git links) tool
I have an alternative solution for the problem - gil (git links) tool
我有这个问题的替代解决方案 - gil (git links) 工具
It allows to describe and manage complex git repositories dependencies.
它允许描述和管理复杂的 git 存储库依赖项。
Also it provides a solution to the git recursive submodules dependency problem.
它还为git recursive submodules 依赖问题提供了解决方案。
Consider you have the following project dependencies: sample git repository dependency graph
考虑您有以下项目依赖项: 示例 git 存储库依赖项图
Then you can define .gitlinks
file with repositories relation description:
然后您可以.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
Each line describe git link in the following format:
每行以以下格式描述 git link:
- Unique name of the repository
- Relative path of the repository (started from the path of .gitlinks file)
- Git repository which will be used in git clone command Repository branch to checkout
- Empty line or line started with # are not parsed (treated as comment).
- 存储库的唯一名称
- 仓库相对路径(从.gitlinks文件路径开始)
- 将在 git clone 命令中使用的 Git 存储库分支以结帐
- 不解析空行或以 # 开头的行(视为注释)。
Finally you have to update your root sample repository:
最后,您必须更新您的根示例存储库:
# Clone and link all git links dependencies from .gitlinks file
gil clone
gil link
# The same result with a single command
gil update
As the result you'll clone all required projects and link them to each other in a proper way.
因此,您将克隆所有必需的项目并以适当的方式将它们相互链接。
If you want to commit all changes in some repository with all changes in child linked repositories you can do it with a single command:
如果要提交某个存储库中的所有更改以及子链接存储库中的所有更改,您可以使用单个命令来完成:
gil commit -a -m "Some big update"
Pull, push commands works in a similar way:
拉、推命令的工作方式类似:
gil pull
gil push
Gil (git links) tool supports the following commands:
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
More about git recursive submodules dependency problem.