使用 Git-Svn 克隆非标准 Svn 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/572893/
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:11:23  来源:igfitidea点击:

Cloning a Non-Standard Svn Repository with Git-Svn

svngitgit-svnclone

提问by Rob Wilkerson

I'm relatively new to Git, but I've found it so easy to work with at home that I'd like to use it at work where our projects are stored in Svn repositories. Unfortunately, the repositories are slightly non-standard and I'm having trouble getting them cloned. Sure, they all have trunk, branches/ and tags/, but branches/ and tags/ have subdirectories before hitting the realproject directories:

我对 Git 比较陌生,但我发现它在家里很容易使用,所以我想在我们的项目存储在 Svn 存储库中的工作中使用它。不幸的是,存储库有点不标准,我无法克隆它们。当然,它们都有主干、分支/和标签/,但分支/和标签/在进入真正的项目目录之前有子目录:

trunk/
branches/maintenance/release1
branches/maintenance/release2
...
branches/development/feature1
branches/development/feature2
...
tags/build/build1
tags/build/build2
...
tags/release/release1
tags/release/release2

After cloning:

克隆后:

$ git svn clone -s --prefix=svn/ https://mydomain.com/svnproject
$ git branch -r
  development
  development@1340
  maintenance
  maintenance@1340
  tags/build
  tags/build@1340
  tags/release
  tags/release@1340
  trunk
  trunk@1340 

I get none of the actual project branches or tags. I actually need to be able to work on the trunk, one maintenance branch and one development branch. I've tried this approach in addition to several hacks at modifying the config, but nothing is working for me.

我没有得到任何实际的项目分支或标签。我实际上需要能够在主干、一个维护分支和一个开发分支上工作。除了修改配置的几个技巧外,我还尝试了这种方法,但没有任何效果对我有用。

Is there any way I can get the key components of my non-standard Svn project into a local git repository so that I can easily move between them?

有什么方法可以将我的非标准 Svn 项目的关键组件放入本地 git 存储库,以便我可以轻松地在它们之间移动?

Many thanks.

非常感谢。

UPDATE: I should add that I can't do a wholesale switch to Git (yet). There are other team members involved and an international presence. The logistics of the transition are more than I'm willing to undertake until I'm much more comfortable with Git; as I mentioned, I'm still pretty new. I've barely scratched the surface of its capabilities.

更新:我应该补充一点,我不能批量切换到 Git(还)。还有其他团队成员参与其中并具有国际影响力。过渡的后勤工作超出了我的意愿,直到我对 Git 更加熟悉为止;正如我所提到的,我还是个新手。我几乎没有触及它的功能的表面。

回答by Rob Wilkerson

Lee B was right. The answer, provided by doener in #git, is to upgrade Git to 1.6.x (I had been using 1.5.x). 1.6.x offers deep cloning so that multiple wildcards can be used with the --branchesoption:

李B是对的。doener 在 #git 中提供的答案是将 Git 升级到 1.6.x(我一直在使用 1.5.x)。1.6.x 提供深度克隆,以便多个通配符可以与--branches选项一起使用:

$ git svn clone https://svn.myrepos.com/myproject web-self-serve \ 
          --trunk=trunk --branches=branches/*/* --prefix=svn/
$ git branch -r
  svn/development/sandbox1
  svn/development/feature1
  svn/development/sandbox2
  svn/development/sandbox3
  svn/development/model-associations
  svn/maintenance/version1.0.0
  svn/trunk

Exactly what I needed. Thanks for the insight, all.

正是我需要的。谢谢大家的见解。

回答by VonC

Could you try nirvdrum's svn2git(seems the most up-to-date) in order to import your svn into a git repository ?
(Early 2009, Paulmentioned this iteman's svn2gitin replacement of this original jcoglan's svn2git, which was, as his author mentioned: "a quick hack to get my code out of Subversion")

您能否尝试nirvdrum 的 svn2git(似乎是最新的)以便将您的 svn 导入 git 存储库?
(2009 年初,Paul提到了这个iteman 的 svn2git来代替原来的 jcoglan 的 svn2git,正如他的作者所说:“快速破解让我的代码脱离 Subversion”)

It is better than git svn clonebecause if you have this code in svn:

这比git svn clone因为如果您在 svn 中有此代码要好 :

  trunk
    ...
  branches
    1.x
    2.x
  tags
    1.0.0
    1.0.1
    1.0.2
    1.1.0
    2.0.0

git-svnwill go through the commit history to build a new git repo.
It will import all branches and tags as remote svn branches, whereas what you really want is git-native local branches and git tag objects.
So after importing this project, you would get:

git-svn将通过提交历史来构建一个新的 git repo。
会将所有分支和标签导入为远程 svn 分支,而您真正想要的是 git-native local branch 和 git tag objects
所以导入这个项目后,你会得到:

  $ git branch
  * master
  $ git branch -a
  * master
    1.x
    2.x
    tags/1.0.0
    tags/1.0.1
    tags/1.0.2
    tags/1.1.0
    tags/2.0.0
    trunk
  $ git tag -l
  [ empty ]

After svn2git is done with your project, you'll get this instead:

在 svn2git 完成你的项目后,你会得到这个:

  $ git branch
  * master
    1.x
    2.x
  $ git tag -l
    1.0.0
    1.0.1
    1.0.2
    1.1.0
    2.0.0


Of course, this solution is not meant as a one-way trip.

当然,这种解决方案并不意味着单程旅行。

You can always go back to your svn repository, with... git2svn(also present there)

您可以随时返回到您的 svn 存储库,使用... git2svn(也出现在那里

The idea remain:

思路依旧:

  • SVN at work as a central repository.

  • Git "elsewhere" to quickly experiment amongst multiple Git-private branches.

  • import backonly consolidated Git branches into official SVN branches.

  • SVN 作为中央存储库工作。

  • Git“其他地方”可以在多个 Git 私有分支之间快速进行试验。

  • 仅将合并的 Git 分支导入回官方 SVN 分支。

回答by joshwa

For repo layouts not served by plain wildcards: (from my answerto this related question)

对于不由普通通配符提供的回购布局:(来自这个相关问题的回答

The current git-svn manpagesays:

当前的git-svn的手册页说:

It is also possible to fetch a subset of branches or tags by using a comma-separated list of names within braces. For example:

也可以通过在大括号内使用逗号分隔的名称列表来获取分支或标签的子集。例如:

[svn-remote "huge-project"]
     url = http://server.org/svn
     fetch = trunk/src:refs/remotes/trunk
     branches = branches/{red,green}/src:refs/remotes/branches/*
     tags = tags/{1.0,2.0}/src:refs/remotes/tags/*