DJ.
DJ.

Reputation: 6774

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.

Upvotes: 15

Views: 7249

Answers (4)

DJ.
DJ.

Reputation: 6774

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

Upvotes: 28

john liao
john liao

Reputation: 257

  • git svn clone http://svnrepo/svn/trunk/newProject
  • git remote add origin ../original-git-repo
  • git fetch origin
  • git checkout -b lmaster remotes/origin/master
  • git rebase master
  • git svn rebase
  • git svn dcommit

Upvotes: 0

me_and
me_and

Reputation: 15634

The easiest way to do this is to just svn import the Git directory. That will lose you your Git commit history, however.

First of all, make sure the .git directory won't be imported by setting the global-ignores in the Subversion config file. Open your ~/.subversion/config file (that'll be in something like C:\Users\username\.subversion\config on Windows), find the section starting [miscellany], and add a line directly underneath reading as below:

global-ignores = .git

(if you already have a line with global-ignores = that doesn't have a # in front of it, then just add .git to the end of that line.)

Next, run the below:

svn import <path-to-local-git-repository> https://svnrepohost/trunk/newProject

That should copy the contents of the local Git repository onto the server exactly where you want it.

Upvotes: 1

Dmitry Pavlenko
Dmitry Pavlenko

Reputation: 8958

You may use SubGit.

$ svnadmin create repo.svn
$ subgit configure repo.svn                                                                                                                                                              

...                                                                                                                                                                           

            CONFIGURATION SUCCESSFUL                                                                                                                                                                                   

            Adjust '/tmp/repo.svn/conf/subgit.conf' file                                                                                                                                                               
            and then run                                                                                                                                                                                               
                subgit install "repo.svn"                                                                                                                                                                              
            to complete SubGit installation.
$ nano repo.svn/conf/subgit.conf #edit to set git.default.repository=path/to/your/bare/git/repository
$ subgit install repo.svn

I would also recommend you to create a bare clone of your Git repository and to specify path to it (in git.default.repository) instead of your original repository. I.e.

$ git clone --bare path/to/your/original/repository path/to/your/bare/git/repository

After "subgit install" command the repositories (repo.svn and repo.git) will be in continuos synchronization (triggered by pre-receive hook in Git [that starts on pushing to your bare repository] and pre-commit in SVN). To stop synchronization you may run

$ subgit uninstall repo.svn

Upvotes: 0

Related Questions