Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import svn branches and tags into git-svn?

Tags:

git

svn

git-svn

I have got a central SVN repository I must commit to, but I've got a passion for git (like any other developer I know). The case is well known.

Then I read about git-svn and gave it a try. Since I don't need the full history, just from two months or so, I did like this:

git svn clone -r 34000 -s https://svn.ourdomain.com/svn/repos/Project/SubProject 

SubProject had, as usual, the subdirectories trunk, tags and branches. Great.

Then, in order to get the last revision, I did

git svn rebase 

Some downloads later, great. Last revision, logs, etc. Ok, now I'll switch to my feature branch.

$ git branch  * master 
$ git branch -r     trunk 
$ git branch -a   * master   remotes/trunk 

The questions are: Where are my branches? Have I done something wrong? How should I do in order to get my branches in the new git repo?

git-svn, wherever I have read about it, dealt wisely with branches and tags, but the behaviour is not what I expected. Thanks!

EDIT: I have just found out that git svn fetch will do it. But it will get all revisions, which is something I wouldn't like.

like image 701
Luís Guilherme Avatar asked Feb 11 '10 12:02

Luís Guilherme


People also ask

Can you convert SVN to Git?

We've broken down the SVN-to-Git migration process into 5 simple steps: Prepare your environment for the migration. Convert the SVN repository to a local Git repository. Synchronize the local Git repository when the SVN repository changes.

How do I clone a SVN repository?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...

What is the difference between tag and branch in SVN?

There is no difference between branches and tags in Subversion. The only difference is in what the user then does with the directory. Branches are typically created, edited, and then merged back into the trunk. Alternatively, tags are created as a snapshot of the project at a point in time and then never changed.


1 Answers

You'll need several steps.

  1. supply proper trunk, branches and tags folder names and fetch svn repo:

    git svn init -t tags -b branches -T trunk https://mysvn.com/svnrepo git svn fetch 
  2. Since tags in svn are real branches, create git tags from tag branches:

    git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags |  cut -d / -f 3- | while read ref do   echo git tag -a $ref -m 'import tag from svn' done 
  3. Delete tag branches

    git for-each-ref --format="%(refname:short)" refs/remotes/tags | cut -d / -f 2- | while read ref do    echo git branch -rd $ref done 
  4. Since tags marked in the previous step point to a commit "create tag", we need to derive "real" tags, i.e. parents of "create tag" commits.

    git for-each-ref --format="%(refname:short)" refs/tags | while read ref do   tag=`echo $ref | sed 's/_/./g'` # give tags a new name   echo $ref -\> $tag   git tag -a $tag `git rev-list -2 $ref | tail -1` -m "proper svn tag" done 
  5. All we have to do now is to remove old tags.

like image 163
Vanuan Avatar answered Sep 24 '22 11:09

Vanuan