如何在我的git项目中包含外部svn存储库?

时间:2011-03-17 20:39:53

标签: svn git svn-externals

我正在使用 git 作为项目的修订控制软件。我的项目需要使用第三方代码库,该代码库使用 SVN 作为其修订控制软件。 (在这种情况下,第三方代码是一个名为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仓库中有一个例子?我确定这一定是一个普遍需要吗?

3 个答案:

答案 0 :(得分:6)

您可以对svn repo执行git-svn克隆,然后将该repo包含到主Git仓库中,并将其声明为 submodule

简单地记住: git子模块与svn子模块不兼容,因为它们总是引用固定版本。参见:


但是,正如我在“git submodule tracking latest”中提到的那样,你可以从git 1.8.2(2013年3月)通过子模块追踪最新的回购分支

$ git submodule add -b <branch> <repository> [<path>]
$ git submodule update --remote ...

答案 1 :(得分:3)

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

有点脏,但也很简单直接。

当你需要更新时,只需要svn update和git commit。

答案 2 :(得分: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 +分支值连接)的子模块(如果未指定,则HEAD修订版为用过的)。 fetch + branches + tags就像.git / config规范。

如果你不想在第三方项目的分支之间快速切换(我这样做是因为我也想提交子模块),请改用这样的东西。

[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 specification中的更多细节。

对于这种配置,SmartGit与子模块的工作方式与通常的Git子模块一样。