How do I migrate an SVN repository with history to

2018-12-31 06:38发布

I read the Git manual, FAQ, Git - SVN crash course, etc. and they all explain this and that, but nowhere can you find a simple instruction like:

SVN repository in: svn://myserver/path/to/svn/repos

Git repository in: git://myserver/path/to/git/repos

git-do-the-magic-svn-import-with-history \
svn://myserver/path/to/svn/repos \
git://myserver/path/to/git/repos

I don't expect it to be that simple, and I don't expect it to be a single command. But I do expect it not to try to explain anything - just to say what steps to take given this example.

30条回答
十年一品温如言
2楼-- · 2018-12-31 06:47

Here is a simple shell script with no dependencies that will convert one or more SVN repositories to git and push them to GitHub.

https://gist.github.com/NathanSweet/7327535

In about 30 lines of script it: clones using git SVN, creates a .gitignore file from SVN::ignore properties, pushes into a bare git repository, renames SVN trunk to master, converts SVN tags to git tags, and pushes it to GitHub while preserving the tags.

I went thru a lot of pain to move a dozen SVN repositories from Google Code to GitHub. It didn't help that I used Windows. Ruby was all kinds of broken on my old Debian box and getting it working on Windows was a joke. Other solutions failed to work with Cygwin paths. Even once I got something working, I couldn't figure out how to get the tags to show up on GitHub (the secret is --follow-tags).

In the end I cobbled together two short and simple scripts, linked above, and it works great. The solution does not need to be any more complicated than that!

查看更多
只靠听说
3楼-- · 2018-12-31 06:49

Several answers here refer to https://github.com/nirvdrum/svn2git, but for large repositories this can be slow. I had a try using https://github.com/svn-all-fast-export/svn2git instead which is a tool with exactly the same name but was used to migrate KDE from SVN to Git.

Slightly more work to set it up but when done the conversion itself for me took minutes where the other script spent hours.

查看更多
零度萤火
4楼-- · 2018-12-31 06:50

Converting svn submodule/folder 'MyModule' into git with history without tags nor branches.

To retain svn ignore list use the above comments after step 1

查看更多
呛了眼睛熬了心
5楼-- · 2018-12-31 06:51

I suggest getting comfortable with Git before trying to use git-svn constantly, i.e. keeping SVN as the centralized repo and using Git locally.

However, for a simple migration with all the history, here are the few simple steps:

Initialize the local repo:

mkdir project
cd project
git svn init http://svn.url

Mark how far back you want to start importing revisions:

git svn fetch -r42

(or just "git svn fetch" for all revs)

Actually fetch everything since then:

git svn rebase

You can check the result of the import with Gitk. I'm not sure if this works on Windows, it works on OSX and Linux:

gitk

When you've got your SVN repo cloned locally, you may want to push it to a centralized Git repo for easier collaboration.

First create your empty remote repo (maybe on GitHub?):

git remote add origin git@github.com:user/project-name.git

Then, optionally sync your main branch so the pull operation will automatically merge the remote master with your local master, when both contain new stuff:

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

After that, you may be interested in trying out my very own git_remote_branch tool, which helps dealing with remote branches:

First explanatory post: "Git remote branches"

Follow-up for the most recent version: "Time to git collaborating with git_remote_branch"

查看更多
看淡一切
6楼-- · 2018-12-31 06:51

I've posted an step by step guide (here) to convert svn in to git including converting svn tags in to git tags and svn branches in to git branches.

Short version:

1) clone svn from an specific revision number. (the revision number must be the oldest you want to migrate)

git svn clone --username=yourSvnUsername -T trunk_subdir -t tags_subdir -b branches_subdir -r aRevisionNumber svn_url gitreponame

2) fetch svn data. This step it's the one it takes most time.

cd gitreponame
git svn fetch

repeat git svn fetch until finishes without error

3) get master branch updated

git svn rebase

4) Create local branches from svn branches by copying references

cp .git/refs/remotes/origin/* .git/refs/heads/

5) convert svn tags into git tags

git for-each-ref refs/remotes/origin/tags | sed 's#^.*\([[:xdigit:]]\{40\}\).*refs/remotes/origin/tags/\(.*\)$#\2 \1#g' | while read p; do git tag -m "tag from svn" $p; done

6) Put a repository at a better place like github

git remotes add newrepo git@github.com:aUser/aProjectName.git
git push newrepo refs/heads/*
git push --tags newrepo

If you want more details, read my post or ask me.

查看更多
妖精总统
7楼-- · 2018-12-31 06:52

I used the svn2git script and works like a charm.

查看更多
登录 后发表回答