开发者

How do I include a external svn repository in my git project?

开发者 https://www.devze.com 2023-02-18 01:02 出处:网络
I\'m using git as the revision control software for a project. My project needs to use a 3rd party code library which uses SVN for its revision control software. (In this case the 3rd party code is a

I'm using git as the revision control software for a project. My project needs to use a 3rd party code library which uses SVN for its revision control software. (In this case the 3rd party code is a PHP framework called Yii, not that it is very relevant to the question).

Is there a way to set up a ext开发者_开发百科ernal dependency in git that can help pull in code from a external SVN repository and keep it up to date?

If my project was using SVN, it would be trivial to set up because I would just do:

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

...then, whenever I did a svn checkout (or svn update), I would suck down the yii codebase into a local folder called "yii-1.1.6". Can I do something similar in git? Does anyone have an example in a public github repo that I can copy? I'm sure it must be a common need?


You can do a git-svn clone of your svn repo, and then include that repo into your main Git repo, declaring it as a submodule.

Simply remember: git submodules are not compatible with svn submodules, in that they always refer a fixed version. See:

  • "Why are git submodules incompatible with svn externals?"
  • "git submodule svn external"

However, as I mention in "git submodule tracking latest", you can since git 1.8.2 (March 2013) track the latest of a branch of a repo through submodule.

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


You could also just SVN checkout the 3rd party library into your tree and then git add it (including all the .svn subdirectories) to your main project.

Kindof dirty but also kindof simple and straightforward.

When you need to update, just svn update and git commit.


I have exactly the same situation at work. I use SmartGit. I have .gitsvnextmodules file in the Git repository root (committed to 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 displays it as a submodule pointing to "https://url.of.svn/repository/blah/branches/branch" (url+branch values concatenated) at revision 1234 (if it is not specified, HEAD revision is used). fetch+branches+tags are like in .git/config specification.

If you do not want to switch between branches of your 3rd party project quickly (I do because I also want to commit to a submodule), use something like this instead.

[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

More details in .gitsvnextmodules specification.

For this configuration SmartGit works with the submodule in the same manner like it works with usual Git submodules.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号