Search code examples
git-svn

How to import local git repository into svn?


I am working on local git repository and I need to push my local git into existing svn repository. My git repository is pure local git repository, it was not init using git svn clone.

How can I import this local git repo into svn?

Preferably I'ld like to keep the git history being imported into SVN.

Currently the SVN repository is structure as:

https://svnrepohost
           /branches
           /tags
           /trunk
                  /projectA
                  /projectB
                  /newProject

What I need it is to import my git repository into the https://svnrepohost/trunk/newProject above, assuming the newProject folder is empty.


Solution

  • I have finally solved this problem by the following steps:

    1. Setup appropriate project folder in svn to be imported to, for example http://svnrepo/svn/trunk/newProject

    2. Create a new git-svn repository

      git svn clone http://svnrepo/svn/trunk/newProject

    3. Add the git repo that we want to import as remote to the new git-svn repo

      git remote add origin ../original-git-repo

    4. Pull all the data from original-git-repo

      git pull origin master --allow-unrelated-histories

    5. Rebase local repository against svn

      git svn rebase

    6. Commit the changes into svn

      git svn dcommit

    7. Clean up the remote

      git remote delete origin