40

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 real project directories:

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?

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.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
Rob Wilkerson
  • 40,476
  • 42
  • 137
  • 192

3 Answers3

38

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 --branches option:

$ 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.

Oliver
  • 3,815
  • 8
  • 35
  • 63
Rob Wilkerson
  • 40,476
  • 42
  • 137
  • 192
16

Could you try nirvdrum's svn2git (seems the most up-to-date) in order to import your svn into a git repository ?
(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")

It is better than git svn clone because if you have this code in 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.
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 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:

  $ 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)

The idea remain:

  • SVN at work as a central repository.

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

  • import back only consolidated Git branches into official SVN branches.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I saw this comment on another post that was similar to my problem. Unfortunately, I don't think that this will work (though I'll definitely take a closer look at svn2git). I need to interact directly with the Svn repos. There are other team members who aren't ready for Git. – Rob Wilkerson Feb 21 '09 at 12:34
  • +1 - I had a similar problems when I was learning git, until I set up a new repo using svn2git and the problems went away. A more up-to-date version is available at http://github.com/iteman/svn2git/tree/master. – Paul Feb 21 '09 at 17:58
  • @VonC - How to restart the clone if it got interrupted due to network unavailability? – notionquest Sep 28 '16 at 15:43
  • @notionquest 7 years later, I am not too sure how I managed that (I don't think I had that issue back then): it is best to ask a new question, with the exact version of SVN, Git, svn2git and OS used. – VonC Sep 28 '16 at 15:46
  • created new question http://stackoverflow.com/questions/39751091/nirvdrum-svn2git-fetch-from-interrupted-clone – notionquest Sep 28 '16 at 15:59
  • I have this exact same problem as the OP. wondering if git-svn solves this now 10 years later? – mike01010 Jun 20 '20 at 06:50
  • @mike01010 As I mentioned here (https://stackoverflow.com/a/57875524/6309), SubGit could help. – VonC Jun 20 '20 at 16:42
9

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

The current git-svn manpage says:

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/*
Community
  • 1
  • 1
joshwa
  • 1,660
  • 3
  • 17
  • 26
  • I have followed your steps and got 1 tag migrated. I would like to repeat the same for the next couple of tags. I have tried to add third tag {1.0,2.0, 3.0} and execute git svn fetch. But it is not fetching anything from repo. Am I missing anything? – notionquest Sep 28 '16 at 15:41