How do I migrate a flat svn repo to git repo
Asked Answered
S

3

5

I have a flat svn repository which looks like:

my_repo/
├── file1.c
├── file2.c
├── file3.c
└── README

This repo has no branches, or tags and all I am trying to do is convert it to a git repository and maintain the commit history.

I have tried:

git svn clone --trunk=/ -A users.txt svn+ssh://[email protected]/projects/my_repo dest_dir

Which I assumed would work, however, when I navigate into dest_dir and perform git svn fetch, it doesn't seem to fetch anything. Using git log yields:

fatal: bad default revision 'HEAD'

If I use svn checkout svn+ssh://[email protected]/projects/my_repo it returns:

A    my_repo/file1.c
A    my_repo/file2.c
A    my_repo/file3.c
A    my_repo/README
Checked out revision 57.

So the repository is alive and accessible.

I have tried various tools including subgit which was giving me this error: svn: E170003: 'stat' not implemented and I think this is because the server hosting the repository is using an old version of subversion. I have no control over the server so cannot perform an update.

I have also tried using the svn2git, using the command

svn2git svn+ssh://[email protected]/projects/my_repo --rootistrunk -authors users.txt --verbose

but this was giving me another error:

E: 'svn+ssh:/[email protected]/projects/my_repo' is not a complete URL and a separate URL is not specified command failed

This stumped me, and I've no idea why it's not working. Basically I was wondering how I go about turning my svn repo into a git repo while maintaining the history. Hope someone can help me out, or point me in the right direction. Never realised it would be so difficult to transfer this simple repo to git!

Thanks

Stature answered 4/4, 2014 at 19:47 Comment(2)
Are you sure the git svn clone didn't give an error? It should have worked. In addition, after git svn clone, if you go inside the directory and do git svn fetch, what happens?Jamboree
Your SVN server is indeed rather old. Consider using svnsync utility to fetch all SVN revisions to your local machine and then try importing this local repository to Git.Patriciate
B
3

The problem is with svn2git's --rootistrunk argument. Instead of that, try this:

svn2git svn+ssh://[email protected]/projects/my_repo --trunk / --notags --nobranches --authors users.txt --verbose
Beauteous answered 29/10, 2014 at 11:55 Comment(0)
L
3

I had the same problem. Not standard svn repository: no trunk, no tag, no brunch. I checked all possible options of svn2git but didn't have success. As svn2git is just ruby wrapper for git svn, I tried directly git svn and it was ok. Here is what I have done.

Init empty git dir and give svn repository path and the relative paths of trunk, tags and brunches. In my case it is / as I don't have any of those.

1. git svn init http://svnmydomain.com/urlpart/projectname --trunk=/ --tags=/ --branches=/

If svn repo is password protected you will have to supply username and password arguments to the command above but in most cases it won't work as it's a little bit buggy. Instead svn checkout in the current folder. git svn will use svn cash and won't ask you for password.

Check that git config is ok. Type

2. git config --list

You should see this:

svn-remote.svn.url=http://svnmydomain.com/urlpart    
svn-remote.svn.fetch=urlpart/projectname:refs/remotes/origin/trunk
svn-remote.svn.branches=urlpart/projectname/*:refs/remotes/origin/*
svn-remote.svn.tags=urlpart/projectname/*:refs/remotes/origin/tags/*

If git config is not correct, fix it manually by executing

git config <key> <value>

Now when git config is ok you should fetch data from svn and push it to git server

3. git svn fetch
4. git remote add origin git@gitdomain:url/gitproject.git
5. git add .
6. git commit -m "merge from svn"
7. git push origin master

If some people continue to work in svn, you will need to synch svn with git constantly. To do it type:

8. git svn rebase
9. git push origin master 
Lonna answered 25/11, 2016 at 12:46 Comment(0)
R
0

Hit same issue with an old 'flat' SVN repo, following worked with git v2.20.1: (following recipe on http://www.sailmaker.co.uk/blog/2013/05/05/migrating-from-svn-to-git-preserving-branches-and-tags-3/ )

git svn init <SVN https URL> --stdlayout --prefix=svn/ -T /
git svn fetch --all
Rand answered 5/9, 2019 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.