(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
Generate an authors.txt file. This will contain a mapping between your SVN users and your Gitlab users:
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]>
Create a temporary directory init SVN repo
mkdir temp
cd temp
git svn init --no-metadata http://username:[email protected]:81/svn/myrepository
Configure git
git config svn.authorsfile ~/authors.txt
git config --global user.name myusername
git config --global user.email [email protected]
Grab the files and clone them into a new git repo
git svn fetch
git clone . ../myrepository
cd ../myrepository
Setup new repository in gitlab, make sure your user has access to it.
Add a remote gitlab repository
git remote add gitlab gitlab.example.com:gitlab-group/myrepository.git
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
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.
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With