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

3

9

(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

Numerous answered 9/3, 2016 at 19:20 Comment(1)
Had you tried in Linux or windows?Jaquiss
N
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 <[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.

Numerous answered 9/3, 2016 at 19:20 Comment(2)
Of all the different procedures I found on the internet, this one actually worked on the 1st pass. Others had errors, or unexpected results.Lyle
Glad it helped someone else!Numerous
E
8

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"
Endocrinology answered 21/10, 2019 at 16:21 Comment(0)
D
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
Drafty answered 17/10, 2019 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.