How to synchronize a GIT repository with SVN?

后端 未结 2 2040
无人共我
无人共我 2021-01-15 08:49

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 chan

2条回答
  •  清酒与你
    2021-01-15 09:35

    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.

提交回复
热议问题