有没有办法在我的Git存储库中添加Subversion存储库作为Git子模块?
类似于:
git-svn submodule add https://svn.foo.com/svn/proj --stdlayout svn-project
其中https://svn.foo.com/svn/proj
指向Subversion存储库。
我知道有git-svn
可以让用户与Subversion存储库进行交互。所以我在想,也许有一种方法可以用git-svn
签出Subversion存储库,然后将其用作子模块。
发布于 2009-01-21 12:47:32
不是的。最好的办法是在专用的git存储库中设置svn存储库的镜像。
git svn clone -s http://subversion.example.com/ mysvnclone
cd mysvnclone
git remote add origin git@example.com:project.git
git push origin master
然后,您可以将git存储库作为子模块添加到原始项目中。
cd /path/to/gitproject
git submodule add git://example.com/project.git -- svn-project
git add svn-project
git commit -m "Add submodule"
在svn:externals和git子模块之间有一个概念上的区别,如果您从subversion的角度来处理这一点,可能会让您陷入困境。Git子模块与您提供的修订版本相关联。如果"upstream“改变了,那么你必须更新子模块的引用。
因此,当我们与上游subversion重新同步时:
cd /path/to/mysvnclone
git svn rebase
git push
..。git项目将仍然使用我们之前提交的原始版本。要更新为svn头文件,您必须使用
cd /path/to/gitproject/svn-project
git checkout master
git pull
cd ..
git add svn-project
git commit -m"Update submodule"
发布于 2009-05-18 14:53:32
我刚经历了这一切。我正在做一些类似于rq的事情,但略有不同。我设置了一台服务器来托管我需要的svn repos的这些git克隆。在我的例子中,我只想要只读版本,并且需要服务器上的纯repo。
在我运行的服务器上:
GIT_DIR=<projectname>.git git init
cd <projectname>.git/
GIT_DIR=. git svn init svn://example.com/trunk
GIT_DIR=. git svn fetch
git gc
这将设置我的纯repo,然后我有一个cron脚本来更新它:
#!/usr/bin/python
import os, glob
GIT_HOME='/var/www/git'
os.chdir(GIT_HOME)
os.environ['GIT_DIR']='.'
gits = glob.glob('*.git')
for git in gits:
if not os.path.isdir(git):
continue
os.chdir(os.path.join(GIT_HOME, git))
if not os.path.isdir('svn/git-svn'):
#Not a git-svn repo
continue
#Pull in svn updates
os.system('git svn fetch && git gc --quiet')
#fix-svn-refs.sh makes all the svn branches/tags pullable
os.system('fix-svn-refs.sh')
#Update the master branch
os.system('git fetch . +svn/git-svn:master && git gc --quiet')`
这也需要来自http://www.shatow.net/fix-svn-refs.sh的fix-svn-refs.sh这主要是由:http://gsocblog.jsharpe.net/archives/12启发的
我不确定为什么这里需要git gc
,但是没有它我就不能做git pull
。
所有这些之后,你就可以按照rq的指示使用git子模块了。
发布于 2010-07-19 01:58:12
除了rq所说的之外,另一种方法是使用第三方“外部”项目(http://nopugs.com/ext-tutorial),它更好地模拟了svn外部引用的工作方式。使用外部,您可以跟踪git或svn存储库,并且将您的更改向上推送到这些存储库看起来更容易。但是,它要求项目成员下载并安装单独的包。
我还没有使用子模块或外部变量;但是,我花了几个小时阅读了所有替代方案,看起来外部变量会更适合我的需求。在Jon Loeliger (http://oreilly.com/catalog/9780596520120)的“使用Git进行版本控制”的第15章中,有一个关于这些和其他自定义方法的很好的讨论,我强烈推荐。
https://stackoverflow.com/questions/465042
复制相似问题