8

(I'm posting this question with the intention of answering it myself as I could not find the answer elsewhere. Hopefully it will help others who run into the same issue and it will help me next time I'm trying to do it.)

The Challenge

I want to convert an SVN repository to a locally hosted gitlab GIT repository and maintain history.

The Setup

Gitlab 8.5, Ubuntu 14.04 LTS, subversion 1.8.8

The Problem

Initial attempts to convert from svn to git using git-svn or svn2git resulted in the following error.

Error

svn-remote.svn: remote ref '//example.com:81/svn/myrepository/trunk:refs/remotes/trunk' must start with 'refs/'

What I've tried

I've followed both guides in the external references below.

External References used

Matt
  • 5,315
  • 1
  • 30
  • 57

3 Answers3

13
  1. Generate an authors.txt file. This will contain a mapping between your SVN users and your Gitlab users:

    • From an existing svn repository: svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt
    • Otherwise, manually create it following this format:

      oldSVNusername = newGitlabUsername <gitlabRegisteredEmailAddress@example.com>

  2. Create a temporary directory init SVN repo

    • mkdir temp
    • cd temp
    • git svn init --no-metadata http://username:password@example.com:81/svn/myrepository
  3. Configure git

    • git config svn.authorsfile ~/authors.txt
    • git config --global user.name myusername
    • git config --global user.email myusername@example.com
  4. Grab the files and clone them into a new git repo

    • git svn fetch
    • git clone . ../myrepository
    • cd ../myrepository
  5. Setup new repository in gitlab, make sure your user has access to it.

  6. Add a remote gitlab repository

    • git remote add gitlab gitlab.example.com:gitlab-group/myrepository.git
  7. Double check your configuration in myrepository/.git/config (especially the URL line)

    [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = /root/temp/. fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = gitlab merge = refs/heads/master [remote "gitlab"] url = http://gitlab.example.com/gitlab-group/myrepository.git fetch = +refs/heads/*:refs/remotes/gitlab/* [user] name = myusername

  8. Push it all upstream

    • git push --set-upstream gitlab master

Now you should have all the files and history converted to git and displaying in gitlab.

Matt
  • 5,315
  • 1
  • 30
  • 57
  • Of all the different procedures I found on the internet, this one actually worked on the 1st pass. Others had errors, or unexpected results. – Paul Apr 26 '18 at 13:49
  • Glad it helped someone else! – Matt Apr 27 '18 at 15:43
7

Removing the leading /slash works for me:

This will not work:

git svn clone "http://..." --prefix=svn/ --trunk=/trunk --branches=/branches --tags=/tags  --authors-file "authors-transform.txt" "C:\Temp\GitRepos"

This works:

git svn clone "http://..." --prefix=svn/ --trunk=trunk --branches=branches --tags=tags  --authors-file "authors-transform.txt" "C:\Temp\GitRepos"
Minh Nguyen
  • 2,106
  • 1
  • 28
  • 34
1

What it woked for me was deleting the .git directory and the run the next command :

git svn clone --authors-file=authors.txt --no-metadata http://svn.companie.com/REP/mock/ -s mock