docs:git:importing_an_svn_repository

This is an old revision of the document!


importing an svn repository

  1. create a text file somewhere (~/Desktop/users.txt) to map the svn users to git users
    jdoe = John Doe <jdoe@example.com>
  2. create a project directory, and change to it
    mkdir myproject.git
    cd myproject.git
  3. initialize an empty git repository
    git svn init -s http://host/path/to/your/svn/repo/project/trunk --no-metadata
    • note the -s flag sets the default svn structure for /branches /tags /trunk; if this isn't how your repo is set up, you can use the -T -b -t flags
  4. set up the user file for mapping
    git config svn.authorsfile ~/Desktop/users.txt
  5. import the svn repository
    git svn fetch
  6. sync with svn (like running svn update)
    git svn rebase
  7. use the master branch to push to svn, and create git only branches for your local development
  8. when you have a commit on the master branch ready to push to svn, do this
    git svn dcommit
  9. since it takes so long to pull full svn history into a git repo, you may want to do this once and then set up a git repo that others can clone, if other users want to use git on a large project

To get in the right frame of mind, don't think of exporting your entire svn repository, but rather export project by project. Export the trunk of your projects and forget about the branches. If you need data from the branches, merge it first.

  1. create a text file somewhere (~/Desktop/users.txt) to map the svn users to git users
    jdoe = John Doe <jdoe@example.com>
  2. create a temporary project directory, and change to it
    mkdir myproject_tmp
    cd myproject_tmp
  3. initialize an empty git repository
    git svn init http://host/path/to/your/svn/repo/project/trunk --no-metadata
    • :!: for some reason I've recently had trouble starting this process with git svn init, so I've been doing git svn clone instead. It looks like this:
      git svn clone file:///cygdrive/h/svn/project/trunk myproject_tmp --no-metadata
  4. set up the user file for mapping
    git config svn.authorsfile ~/Desktop/users.txt
  5. import the svn repository
    git svn fetch
  6. change up one directory, and clone this newly created repository (this cleans up all svn stuff)
    cd ..
    git clone myproject_tmp myproject
  7. the myproject_tmp directory can now be removed, and the origin remote
    rm -Rf myproject_tmp
    cd myproject
    git remote rm origin
  8. if you want to push this out to a shared repo, you can do it like this
    cd /path/to/shared/dir
    mkdir project.git
    cd project.git
    git init --bare --shared
    cd /path/to/myproject
    git push /path/to/shared/dir/myproject.git refs/heads/master
    (you can push other refs if you want at this point, if they should be public)
    
    (then I usually git clone from this shared repo for good measure to make sure it all works; your merge paths will work by default too)
  9. you should also consider that although svn allows empty directories as part of the repo, git does not; we usually fix this by adding empty files named .emptydir in any directory that needs it
  • docs/git/importing_an_svn_repository.1278540325.txt.gz
  • Last modified: 2010/07/07 16:05
  • by billh