Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svn to git conversion: Correct remote ref must start with 'refs/' error

(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

  • http://doc.gitlab.com/ce/workflow/importing/migrating_from_svn.html
  • http://john.albin.net/git/convert-subversion-to-git
like image 417
Matt Avatar asked Mar 09 '16 19:03

Matt


3 Answers

  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 <[email protected]>

  2. Create a temporary directory init SVN repo

    • mkdir temp
    • cd temp
    • git svn init --no-metadata http://username:[email protected]:81/svn/myrepository
  3. Configure git

    • git config svn.authorsfile ~/authors.txt
    • git config --global user.name myusername
    • git config --global user.email [email protected]
  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.

like image 135
Matt Avatar answered Oct 27 '22 01:10

Matt


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"
like image 34
Minh Nguyen Avatar answered Oct 26 '22 23:10

Minh Nguyen


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
like image 21
wizardInCloud Avatar answered Oct 27 '22 00:10

wizardInCloud