3

我正在使用git作为项目的修订控制软件。我的项目需要使用SVN作为其版本控制软件的第 3 方代码库。(在这种情况下,第 3 方代码是一个名为Yii的 PHP 框架,并不是说它与问题非常相关)。

有没有办法在 git 中设置外部依赖项,可以帮助从外部SVN存储库中提取代码并使其保持最新?

如果我的项目使用的是 SVN,那么设置起来很简单,因为我会这样做:

> svn propset svn:externals yii-1.1.6 https://yii.googlecode.com/svn/tags/1.1.6/framework

...然后,每当我执行svn checkout(或svn update)时,我都会将 yii 代码库吸到一个名为“ yii-1.1.6”的本地文件夹中。我可以在 git 中做类似的事情吗?有没有人在我可以复制的公共 github 存储库中有一个示例?我确定这一定是一个共同的需求?

4

3 回答 3

6

您可以对您的 svn 存储库进行 git-svn 克隆,然后将该存储库包含到您的主 Git 存储库中,并将其声明为子模块

只需记住:git 子模块与 svn 子模块不兼容,因为它们总是引用固定版本。看:


git submodule但是,正如我在“跟踪最新”中提到的,自 git 1.8.2(2013 年 3 月)以来,您可以通过 submodule 跟踪 repo 的最新分支

$ git submodule add -b <branch> <repository> [<path>]
$ git submodule update --remote ...
于 2011-03-17T20:50:04.263 回答
3

您也可以只 SVN 将 3rd 方库签出到您的树中,然后 git 将它(包括所有 .svn 子目录)添加到您的主项目中。

有点脏,但也有点简单明了。

当您需要更新时,只需 svn update 和 git commit 即可。

于 2011-05-26T16:12:40.180 回答
0

我在工作中也有同样的情况。我使用 SmartGit。我在 Git 存储库根目录中有 .gitsvnextmodules 文件(提交给 Git)。

[submodule "anyString"]
        path = path/to/svn/submodule
        url = https://url.of.svn/repository/blah
        revision = 1234
        branch = branches/branch #or it can be "trunk"
        fetch = trunk:refs/remotes/svn/trunk
        branches = branches/*:refs/remotes/svn/*
        tags = tags/*:refs/remote-tags/svn/*
        remote = svn
        type = dir

SmartGit 在修订版 1234 将其显示为指向“https://url.of.svn/repository/blah/branches/branch”(url+branch 值连接)的子模块(如果未指定,则使用 HEAD 修订版)。fetch+branches+tags 类似于 .git/config 规范。

如果您不想在 3rd 方项目的分支之间快速切换(我这样做是因为我也想提交一个子模块),请改用类似的东西。

[submodule "alternativeSubmodule"]
        path = path/to/svn/submodule
        url = https://url.of.svn/repository/blah/branches/branch
        revision = 1234
        branch = /
        fetch = :refs/remotes/svn/git-svn
        remote = svn
        type = dir

.gitsvnextmodules规范中的更多详细信息。

对于此配置,SmartGit 与子模块的使用方式与普通 Git 子模块的使用方式相同。

于 2012-05-12T23:27:52.383 回答