简体   繁体   English

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

[英]Cloning a Non-Standard Svn Repository with Git-Svn

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. 我对Git比较陌生,但我发现在家工作很容易,我想在我们的项目存储在Svn存储库中的工作中使用它。 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 real project directories: 当然,它们都有trunk,branches /和tags /,但是在命中实际项目目录之前,branch /和tags /都有子目录:

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). 更新:我应该补充一点,我不能批量切换到Git(尚)。 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; 转型的后勤工作比我更愿意承担,直到我对Git更加满意; as I mentioned, I'm still pretty new. 正如我所提到的,我还是很新的。 I've barely scratched the surface of its capabilities. 我几乎没有触及其功能的表面。

Lee B was right. 李B是对的。 The answer, provided by doener in #git, is to upgrade Git to 1.6.x (I had been using 1.5.x). doener在#git中提供的答案是将Git升级到1.6.x(我一直在使用1.5.x)。 1.6.x offers deep cloning so that multiple wildcards can be used with the --branches option: 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. 感谢所有人的洞察力。

Could you try nirvdrum's svn2git (seems the most up-to-date) in order to import your svn into a git repository ? 您可以尝试nirvdrum的svn2git (似乎是最新的),以便将您的svn导入git存储库吗?
(Early 2009, Paul mentioned this iteman's svn2git in replacement of this original jcoglan's svn2git , which was, as his author mentioned: "a quick hack to get my code out of Subversion") (2009年初, Paul提到了这个iteman的svn2git来代替这个原始的jcoglan的svn2git ,就像他的作者提到的那样:“快速破解我的代码脱离Subversion”)

It is better than git svn clone because 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-svn will go through the commit history to build a new git repo. git-svn将通过提交历史记录来构建一个新的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 . 它将所有分支和标签导入为远程svn分支,而你真正想要的是git-native本地分支和git标记对象
So after importing this project, you would get: 因此,在导入此项目后,您将获得:

  $ 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. SVN作为中央存储库工作。

  • Git "elsewhere" to quickly experiment amongst multiple Git-private branches. Git“在其他地方”快速在多个Git私有分支机构中进行实验。

  • import back only consolidated Git branches into official SVN branches. 导入合并的Git分支到官方SVN分支。

For repo layouts not served by plain wildcards: (from my answer to this related question ) 对于普通通配符不提供的回购布局:(来自 对此相关问题的回答

The current git-svn manpage says: 当前的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/*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM