Skip to content

Instantly share code, notes, and snippets.

@beall49
Last active June 27, 2018 19:24
Show Gist options
  • Save beall49/ca7539ccaccc8c426c1f951549e359e1 to your computer and use it in GitHub Desktop.
Save beall49/ca7539ccaccc8c426c1f951549e359e1 to your computer and use it in GitHub Desktop.
How to migrate svn to git
  1. Create New Volume

    • If you're on OS X you'll have to do this. It creates a new volume (named migration) on your machine under ~ that's 1GB

      java -jar ~/svn-migration-scripts.jar create-disk-image 1  migration
  2. Create authors list.

    Important, if you get any kind of error about authors here or in the cloning, fix the username manually

    • if you have the repo already pulled from SVN
      svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt
    • You can use the migration jar and just add the svn repo
      java -jar svn-migration-scripts.jar authors [repo-url] > authors.txt
  3. Move authors list and jar to new disk image (or folder where you want it)

  4. Clone SVN Repo (this will take forever)

    • FYI, you can use git svn clone file:///e/svn_repo_on_E_drive to clone a local repo
      git svn clone --stdlayout --authors-file=authors.txt  --no-metadata [svn-repo-url] [repo-name] && cd [repo-name]

    ❗ ❗ ❗ ❗ ❗ ❗ ❗ ❗ ❗ ❗ ❗ ❗ ❗

    If you get any message or error you'll need to fix your authors.txt (probably missing a person, add them manually)

  5. Run these commands in this order, these should clean all of the branches/tags/refs

      for b in `git branch -a | grep "remotes/origin/tags/"`; do t=`echo $b | cut -d - -f 2`; git tag $t $b; done 
      for b in $(git for-each-ref --format='%(refname:short)' refs/remotes); do git branch $b refs/remotes/$b && git branch -D -r $b; done
      for p in $(git for-each-ref --format='%(refname:short)' | grep @); do git branch -D $p; done
  6. Create .gitignore

    printf '%s\n' ' .data' '*/classes' 'cwallet.sso' '*.swp' '*.lck' '.DS_Store' >.gitignore
7) Review the local repo, make sure it's all there     
    ```sh
    git tag -l
    git branch -a
    git log  (exit with q) 
    ```

8) Commit changes
      ```sh
      git add --all
      git commit -am "added .gitignore, svn => git merge
      ```
  1. Add remote (obviously make a repo)

    git remote add origin [repo-url]
  2. Push to remote

    git push --all
    git push --tags
  3. Optional (Delete branches and tags you don't want)

    git branch | grep -v "master" | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment