是否可以将 Subversion 存储库作为 Git 子模块?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/465042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:06:43  来源:igfitidea点击:

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

svngitgit-svn

提问by davitenio

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

有没有办法在我的 Git 存储库中添加一个 Subversion 存储库作为 Git 子模块?

Something like:

就像是:

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

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

https://svn.foo.com/svn/proj点Subversion库。

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

我知道git-svn它允许人们与 Subversion 存储库进行交互。所以我在想,也许有一种方法可以检出 Subversion 存储库,git-svn然后将其用作子模块。

采纳答案by richq

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

不。最好的办法是在专用的 git 存储库中设置 svn 存储库的镜像。

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

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

然后就可以将git仓库作为子模块添加到原项目中

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.

svn:externals 和 git submodule 之间有一个概念上的区别,如果您从颠覆的角度来处理这个问题,可能会绊倒您。git 子模块与您提供的修订版挂钩。如果“上游”发生变化,则必须更新子模块的引用。

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

... git 项目仍将使用我们之前提交的原始修订版。要更新到 svn HEAD,您必须使用

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

回答by sherbang

I just went through this. I'm doing something similar to rq, but slightly different. I setup one of my servers to host these git clones of the svn repos I need. In my case I only want read-only versions, and need a bare repo on the server.

我刚刚经历了这个。我正在做类似于 rq 的事情,但略有不同。我设置了一台服务器来托管我需要的 svn 存储库的这些 git 克隆。在我的情况下,我只想要只读版本,并且需要服务器上的裸仓库。

On the server I run:

在我运行的服务器上:

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

This sets up my bare repo, then I have a cron script to update it:

这设置了我的裸仓库,然后我有一个 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')`

This also requires fix-svn-refs.sh from http://www.shatow.net/fix-svn-refs.shThis was mostly inspired by: http://gsocblog.jsharpe.net/archives/12

这也需要来自http://www.shatow.net/fix-svn-refs.sh 的fix-svn-refs.sh 这主要是受以下启发:http: //gsocblog.jsharpe.net/archives/12

I'm not sure why the git gcis needed here, but I wasn't able to do a git pullwithout it.

我不确定为什么git gc这里需要 ,但是git pull没有它我就无法做到。

So after all this you can then use git submodule following rq's instructions.

因此,在所有这些之后,您可以按照 rq 的说明使用 git submodule。

回答by vadishev

Currently git-svndoesn't support svn:externals. But there are two other tools which can help you:

目前git-svn不支持svn:externals。但是还有另外两个工具可以帮助您:

  1. SubGit

    SubGitis server-side solution, it enables Git access to Subversion repository and vice versa. You may refer to documenationfor more details, but in general it is fairly easy to use SubGit:

    $ subgit configure --layout auto $SVN_URL $GIT_REPO
    

    Above command will detect branches layout in the SVN project and then will create empty bare Git repository ready to mirror SVN project. You may be asked for credentials unless those are already stored in the SVN credentials cache at ~/.subversion directory. You can also adjust $GIT_REPO/subgit/authors.txtto map SVN author names to Git identities.

    $ subgit install $GIT_REPO
    $ ... let initial translation complete ... 
    $ TRANSLATION SUCCESSFUL
    

    At this moment you have Subversion repository connected to newly created Git repository. SubGit translates SVN revision into Git commit on every svn commitand Git commit into SVN revision on every git push.

  1. 子Git

    SubGit是服务器端解决方案,它允许 Git 访问 Subversion 存储库,反之亦然。您可以参考文档了解更多详细信息,但总的来说,使用 SubGit 相当容易:

    $ subgit configure --layout auto $SVN_URL $GIT_REPO
    

    上面的命令将检测 SVN 项目中的分支布局,然后将创建空的裸 Git 存储库准备镜像 SVN 项目。您可能会被要求提供凭据,除非这些凭据已经存储在 ~/.subversion 目录的 SVN 凭据缓存中。您还可以调整$GIT_REPO/subgit/authors.txt以将 SVN 作者姓名映射到 Git 身份。

    $ subgit install $GIT_REPO
    $ ... let initial translation complete ... 
    $ TRANSLATION SUCCESSFUL
    

    此时,您已将 Subversion 存储库连接到新创建的 Git 存储库。SubGitsvn commit在每个git push.

Everything you need further is to make Git repository available to committers. Take a look at git-http-backendfor that. Then you can add created Git repository as a usual submodule. SubGit is also availale as an add-on for the Bitbucket Server, to find out more check out here. So, there is no need to use any external tools like git-svnor any other.

您需要进一步做的就是让提交者可以使用 Git 存储库。看看git-http-backend。然后您可以将创建的 Git 存储库添加为通常的子模块。SubGit 也可用作 Bitbucket Server 的附加组件,要了解更多信息,请查看此处。因此,无需使用任何外部工具,例如git-svn或任何其他工具。

SubGit is proprietary software but it's free for small companies (up to 10 committers), academic and open-source projects.

SubGit 是专有软件,但对小公司(最多 10 个提交者)、学术和开源项目免费。

  1. SmartGit

    SmartGit replaces git-svnon client-side. More information on its features you may find here.

    In particular SmartGit does support both git submodulesand svn:externals, you can mix them in your repository.

    SmartGit is proprietary software but it's free for non-commercial usage.

  1. 智能Git

    SmartGit在客户端替换git-svn。您可以在此处找到有关其功能的更多信息。

    特别是 SmartGit 确实支持git 子模块svn:externals,您可以在您的存储库中混合它们。

    SmartGit 是专有软件,但可免费用于非商业用途。

回答by pcuenca

In addition to what rq said, another method would be to use the third-party "externals" project (http://nopugs.com/ext-tutorial), which better mimics how svn external references work. With externals you can track either git or svn repositories, and it looks easier to push your changes upstream to those repos. However, it requires project members to download and install the separate package.

除了 rq 所说的,另一种方法是使用第三方“externals”项目(http://nopugs.com/ext-tutorial),它更好地模仿了 svn 外部引用的工作方式。使用 externals,您可以跟踪 git 或 svn 存储库,并且将您的更改推送到这些存储库看起来更容易。但是,它需要项目成员下载并安装单独的包。

I haven't used submodules or externals yet; however, I've spent a few hours reading about all alternatives and it looks like externals will be a better fit for my needs. There is an excellent discussion about these and other custom methods in Chapter 15 of "Version Control with Git", by Jon Loeliger (http://oreilly.com/catalog/9780596520120), which I strongly recommend.

我还没有使用子模块或外部模块;但是,我花了几个小时阅读所有替代方案,看起来外部组件更适合我的需求。Jon Loeliger ( http://oreilly.com/catalog/9780596520120)的“使用 Git 进行版本控制”的第 15 章中对这些和其他自定义方法进行了很好的讨论,我强烈推荐。

回答by Otto

Piston is being rewritten to support this, and the converse, plus the existing Subversion URL in a Subvresion repoistory and git+git.

Piston 正在被重写以支持这一点,反之亦然,加上 Subvresion 存储库和 git+git 中现有的 Subversion URL。

Check out the piston Github repository.

查看活塞 Github 存储库

Unfortunately it doesn't seem to have been released.

不幸的是,它似乎尚未发布。

回答by mcepl

Well, there is git-remote-testsvn, so I guess something like

嗯,有git-remote-testsvn,所以我想像

git submodule add testsvn::http://www.telegraphics.com.au/svn/bzquips/trunk/ \
    module/bzquips

should work. Does it?

应该管用。可以?