Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
628 views
in Technique[技术] by (71.8m points)

svn - Is it possible to have a Subversion repository as a Git submodule?

Is there a way to add a Subversion repository as a Git submodule in my Git repository?

Something like:

git-svn submodule add https://svn.foo.com/svn/proj --stdlayout svn-project

Where https://svn.foo.com/svn/proj points to a Subversion repository.

I know there is git-svn which allows one to interact with a Subversion repository. So I am thinking, maybe there is a way to checkout a Subversion repository with git-svn and then use it as a submodule.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No. Your best bet would be to set up a mirror of the svn repository in a dedicated git repository.

git svn clone -s http://subversion.example.com/ mysvnclone
cd mysvnclone
git remote add origin git@example.com:project.git
git push origin master

Then you can add the git repository as a submodule to the original project

cd /path/to/gitproject
git submodule add git://example.com/project.git -- svn-project
git add svn-project
git commit -m "Add submodule"

There is one conceptual difference between svn:externals and git submodule that may trip you up if you approach this from a subversion point of view. The git submodule is pegged to the revision that you give it. If "upstream" changes, then you have to update your submodule's reference.

So when we resync with the upstream subversion:

cd /path/to/mysvnclone
git svn rebase
git push

... the git project will still use the original revision that we committed earlier. To update to the svn HEAD, you would have to use

cd /path/to/gitproject/svn-project
git checkout master
git pull
cd ..
git add svn-project
git commit -m"Update submodule"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...