2

I am planning to make a fork of an open-source project, but I want to switch to GIT. The project is using SVN, but there is no TRAC available, so I can't just download changesets without having SVN on my PC (not to mention svn diff doesn't allow binary patches).

Is there a way to synchronize my GIT master repository with SVN's HEAD/trunk without keeping another project on my HDD?

jurchiks
  • 1,354
  • 4
  • 25
  • 55

2 Answers2

4

You can synchronize SVN with Git using git-svn(1).

If you have existing Git repository, and want to bind with another SVN repository, you can try some kind of voodoo, see http://blog.experimentalworks.net/2009/07/git-voodoo/.

The blog shows how to convert existing non-git-svn Git repository, to git-svn-enabled Git repository with a new created remote SVN repository. You can modify the voodoo workflow a little to import an existing SVN repository to you Git repository:

  1. Import the trunk as a parallel branch into your existing Git repository

    cd GIT-REPO
    git svn clone --stdlayout SVN-URL .
    
  2. Setup the graft:

    TRUNK_HEAD=`git rev-parse trunk`
    MASTER_INIT=`git rev-list --reverse master | head -1`
    echo $MASTER_INIT $TRUNK_HEAD >.git/info/grafts
    
  3. Find out the range in master branch to be appended to trunk, for example, only the changes start from tag v2.0 will be appended to trunk.

  4. Rebase trunk

    git checkout master
    git rebase --onto trunk v2.0 master
    
  5. Commit to trunk

    git svn dcommit
    

A usage hint: by using grafts with git-svn, you should ensure you won't dcommit empty commits. Otherwise, dcommit will fail. To filter away the empty commits, try

git filter-branch --prune-empty

before the first time dcommit.

Lenik
  • 13,946
  • 17
  • 75
  • 103
  • I need to do the opposite - sync GIT with SVN. I will be committing to a GIT repository. – jurchiks Jan 08 '11 at 11:44
  • You can do it, too. I have modified my answer to reflect it. – Lenik Jan 08 '11 at 11:48
  • As far as I read, dcommit is for svn commits, but I won't be committing to the svn. BTW, I will be using EGit for Eclipse, not the console client. – jurchiks Jan 08 '11 at 12:02
  • Oh. You won't commit to the remote SVN, yes? Then, after `git svn clone` to your local Git repository, you can treat it just as normal Git repository. You will do nothing to dcommit. – Lenik Jan 08 '11 at 12:12
  • So you should mention EGit in your question. I'm using EGit, too, to get the filename status icon work. but I mostly doing git work outside of eclipse. Unfortunately, I didn't find useful git-svn function in EGit, yet. Maybe you should write your own extension. – Lenik Jan 08 '11 at 12:30
  • Well, that's the thing, I will be committing only to my GIT repo, but I want to do with the master the same as Team>Synchronize with Repository. I know it's probably impossible because afaik synchronization checks .svn files/folders which GIT won't have, but IMHO something like that that compares the code between GIT and SVN repos would be extremely useful. – jurchiks Jan 08 '11 at 13:00
1

If you have an access to your SVN repository you may install SubGit into it. Just run

$ subgit install path/to/your/svn/repostiory

All the synchronization will be performed automatically (triggered by SVN and Git hooks). In this case not only master/trunk but all the branches will be in sync (though you can configure its behaviour).

Disclaimer: I'm one of the developers of this product.

zovits
  • 906
  • 16
  • 27
Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38