Reputation: 61098
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.
Upvotes: 1630
Views: 571259
Reputation: 4614
For GitLab users I've put up a gist on how I migrated from SVN here:
https://gist.github.com/leftclickben/322b7a3042cbe97ed2af
svn.domain.com.au
.http
(other protocols should work).git.domain.com.au
and:
dev-team
.ssh [email protected]
).favourite-project
is created in the dev-team
namespace.users.txt
contains the relevant user details, one user per line, of the form username = First Last <[email protected]>
, where username
is the username given in SVN logs. (See first link in References section for details, in particular answer by user Casey).git svn clone --stdlayout --no-metadata -A users.txt http://svn.domain.com.au/svn/repository/favourite-project
cd favourite-project
git remote add gitlab [email protected]:dev-team/favourite-project.git
git push --set-upstream gitlab master
That's it! Reload the project page in GitLab web UI and you will see all commits and files now listed.
git svn clone
command will stop, in which case, update users.txt
, cd favourite-project
and git svn fetch
will continue from where it stopped.trunk
-tags
-branches
layout for SVN repository is required.git svn clone
command stops at the level immediately above trunk/
, tags/
and branches/
.git svn clone
command produces a lot of output, including some warnings at the top; I ignored the warnings.Upvotes: 5
Reputation: 116948
Create a users file (i.e. users.txt
) for mapping SVN users to Git:
user1 = First Last Name <[email protected]>
user2 = First Last Name <[email protected]>
...
You can use this one-liner to build a template from your existing SVN repository:
svn log -q | awk -F '|' '/^r/ {gsub(/ /, "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > users.txt
SVN will stop if it finds a missing SVN user, not in the file. But after that, you can update the file and pick up where you left off.
Now pull the SVN data from the repository:
git svn clone --stdlayout --no-metadata --authors-file=users.txt svn://hostname/path dest_dir-tmp
This command will create a new Git repository in dest_dir-tmp
and start pulling the SVN repository. Note that the "--stdlayout" flag implies you have the common "trunk/, branches/, tags/" SVN layout. If your layout differs, become familiar with --tags
, --branches
, --trunk
options (in general git svn help
).
All common protocols are allowed: svn://
, http://
, https://
. The URL should target the base repository, something like http://svn.mycompany.com/myrepo/repository. The URL string must not include /trunk
, /tag
or /branches
.
Note that after executing this command it very often looks like the operation is "hanging/frozen", and it's quite normal that it can be stuck for a long time after initializing the new repository. Eventually, you will then see log messages which indicate that it's migrating.
Also note that if you omit the --no-metadata
flag, Git will append information about the corresponding SVN revision to the commit message (i.e. git-svn-id: svn://svn.mycompany.com/myrepo/<branchname/trunk>@<RevisionNumber> <Repository UUID>
)
If a user name is not found, update your users.txt
file then:
cd dest_dir-tmp
git svn fetch
You might have to repeat that last command several times, if you have a large project until all of the Subversion commits have been fetched:
git svn fetch
When completed, Git will checkout the SVN trunk
into a new branch. Any other branches are set up as remotes. You can view the other SVN branches with:
git branch -r
If you want to keep other remote branches in your repository, you want to create a local branch for each one manually. (Skip trunk/master.) If you don't do this, the branches won't get cloned in the final step.
git checkout -b local_branch remote_branch
# It's OK if local_branch and remote_branch are the same names
Tags are imported as branches. You have to create a local branch, make a tag and delete the branch to have them as tags in Git. To do it with tag "v1":
git checkout -b tag_v1 remotes/tags/v1
git checkout master
git tag v1 tag_v1
git branch -D tag_v1
Clone your GIT-SVN repository into a clean Git repository:
git clone dest_dir-tmp dest_dir
rm -rf dest_dir-tmp
cd dest_dir
The local branches that you created earlier from remote branches will only have been copied as remote branches into the newly cloned repository. (Skip trunk/master.) For each branch you want to keep:
git checkout -b local_branch origin/remote_branch
Finally, remove the remote from your clean Git repository that points to the now-deleted temporary repository:
git remote rm origin
Upvotes: 1668
Reputation: 60556
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 [email protected]: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 to deal with remote branches:
First explanatory post: "Git remote branches"
Follow-up for the most recent version: "Time to git collaborating with git_remote_branch"
Upvotes: 62
Reputation: 2672
subgit import --svn-url url://svn.serv/Bla/Bla directory/path/Local.git.Repo
It's all.
+ To update from SVN, a Git repository is created by the first command.
subgit import directory/path/Local.git.Repo
I used a way to migrate to Git instantly for a huge repository.
Of course, you need some preparation.
But you may don't stop the development process, at all.
Here is my way.
My solution looks like:
Migration takes a lot of time for a big SVN repository.
But updating of the completed migration just seconds.
Of course, I'm using SubGit, mama. git-svn makes me Blue Screen of Death. Just constantly. And git-svn is boring me with Git's "filename too long" fatal error.
STEPS
2. Prepare migrate and update commands.
Let's say we do it for Windows (it's trivial to port to Linux).
In a SubGit's installation bin directory (subgit-2.X.X\bin), create two .bat files.
Content of a file/command for the migration:
start subgit import --svn-url url://svn.serv/Bla/Bla directory/path/Local.git.Repo
The "start" command is optional here (Windows). It'll allow to see errors on start and left a shell opened after completion of the SubGit.
You may add here additional parameters similar to git-svn.
I'm using only --default-domain myCompanyDomain.com to fix the domain of the email address of SVN authors.
I have the standard SVN repository's structure (trunk/branches/tags) and we didn't have troubles with "authors mapping". So I'm doing nothing anymore.
(If you want to migrate tags like branches or your SVN have multiple branches/tags folders you may consider using the more verbose SubGit approach)
Tip 1: Use --minimal-revision YourSvnRevNumber to see fast how things boil out (some kind of a debugging).
Especially useful is to see resolved author names or emails.
Or to limit the migration history depth.
Tip 2: Migration may be interrupted (Ctrl + C) and restored by running of the next updating command/file.
I don't advise doing this for big repositories. I have received "Out of memory Java+Windows exception".
Tip 3: Better to create a copy of your result bare repository.
Content of a file/command for updating:
start subgit import directory/path/Local.git.Repo
You may run it any amount of time when you want to obtain the last team's commits to your Git repository.
Warning! Don't touch your bare repository (creation of branches for example).
You'll take the next fatal error:
Unrecoverable error: are out of sync and cannot be synced ... Translating Subversion revisions to Git commits...
3. Run the first command/file. It'll take a loooong time for a big repository. 30 hours for my humble repository.
It's all.
You may update your Git repository from SVN at any time any amount of times by running the second file/command. And before switching your development team to Git.
It'll take just seconds.
There's one more useful task.
Push your local Git repository to a remote Git repository
Is it your case? Let's proceed.
Run:
$ git remote add origin url://your/repo.git
By default your Git can't send big chunks. fatal: The remote end hung up unexpectedly
Let's run for it:
git config --global http.postBuffer 1073741824
524288000 - 500 MB 1073741824 - 1 GB, etc.
Fix your local certificate troubles. If your git-server uses a broken certificate.
I have disabled certificates.
Also your Git server may have a request amount limitations needing to be corrected.
Run with a local Git:
git push origin --mirror
(git push origin '*:*' for old Git versions)
If you get the following: error: cannot spawn git: No such file or directory... For me the full recreation of my repository solves this error (30 hours). You can try the next commands
git push origin --all
git push origin --tags
Or try to reinstall Git (useless for me). Or you may create branches from all you tags and push them. Or, or, or...
Upvotes: 16
Reputation: 812
All in One - shell script for SVN
to GIT
Migration. Mention the GIT
and SVN
details with placeholder <>
#!/bin/bash
######## Project name
PROJECT_NAME="Helloworld"
EMAIL="example mail"
#Credientials Repo
GIT_USER='<git username>'
GIT_PWD='<git password>'
SVN_USER='<svn username>'
SVN_PWD='<svn password>'
######## SVN repository to be migrated # Dont use https - error will be thrown
BASE_SVN="<SVN URL>/Helloworld"
#Organization inside BASE_SVN
BRANCHES="branches"
TAGS="tags"
TRUNK="trunk"
#Credientials
git config --global user.name '<git username>'
git config --global user.password '<git password>'
git config --global credential.helper 'cache --timeout=3600'
######## GIT repository to migrate - Ensure already project created in Git
GIT_URL=https://$GIT_USER:$GIT_PWD@<GIT URL>/Helloworld.git
###########################
#### Don't need to change from here
###########################
#Geral Configuration
ABSOLUTE_PATH=$(pwd)
TMP=$ABSOLUTE_PATH/$PROJECT_NAME
#Branchs Configuration
SVN_BRANCHES=$BASE_SVN/$BRANCHES
SVN_TAGS=$BASE_SVN/$TAGS
SVN_TRUNK=$BASE_SVN/$TRUNK
AUTHORS=$PROJECT_NAME"-authors.txt"
echo '[LOG] Starting migration of '$SVN_TRUNK
echo '[LOG] Using: '$(git --version)
echo '[LOG] Using: '$(svn --version | grep svn,)
mkdir $TMP
echo
echo '[DIR] cd' $TMP
cd $TMP
echo
echo '[LOG] Getting authors'
svn --username $SVN_USER --password $SVN_PWD log -q $BASE_SVN | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2"@"$EMAIL">"}' | sort -u >> $AUTHORS
echo
echo '[RUN] git svn clone --authors-file='$AUTHORS' --trunk='$TRUNK' --branches='$BRANCHES' --tags='$TAGS $BASE_SVN $TMP
git svn clone --authors-file=$AUTHORS --trunk=$TRUNK --branches=$BRANCHES --tags=$TAGS $BASE_SVN $TMP
#Not working so no need to mention it
#--stdlayout $PROJECT_NAME
echo
echo '[RUN] svn ls '$SVN_BRANCHES
svn ls $SVN_BRANCHES
echo
echo 'git branch -a'
git branch -a
echo
echo '[LOG] Getting first revision'
FIRST_REVISION=$( svn log -r 1:HEAD --limit 1 $BASE_SVN | awk -F '|' '/^r/ {sub("^ ", "", $1); sub(" $", "", $1); print $1}' )
echo
echo '[RUN] git svn fetch -'$FIRST_REVISION':HEAD'
git svn fetch -$FIRST_REVISION:HEAD
#Branches and Tags
echo
echo '[RUN] svn ls '$SVN_BRANCHES
for BRANCH in $(svn ls $SVN_BRANCHES); do
echo git branch ${BRANCH%/} remotes/svn/${BRANCH%/}
git branch ${BRANCH%/} remotes/svn/${BRANCH%/}
done
git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/origin/tags | grep -v "@" | cut -d / -f 3- |
while read ref
do
echo git tag -a $ref -m 'import tag from svn'
git tag -a $ref -m 'import tag from svn'
done
git for-each-ref --format="%(refname:short)" refs/remotes/origin/tags | cut -d / -f 1- |
while read ref
do
git branch -rd $ref
done
echo
echo 'git tag'
git tag
echo
echo 'git show-ref --tags'
git show-ref --tags
echo
echo '[RUN] git remote add origin '$GIT_URL
git remote add origin $GIT_URL
echo
echo '[RUN] git push'
git push origin --all --force
git push origin --tags
#echo git branch -d -r trunk
#git branch -d -r trunk
git config --global credential.helper cache
echo 'Successful.'
.git
folder.SVN
that should be available under this .git/refs/heads
folder.SVN
then do manually copy branches files from .git/refs/remotes/origin/<branches>
to .git/refs/heads
master
) and ignore if any tags
or trunk
.branches
and tags
in git repositories.Upvotes: 0
Reputation: 418
First, credit to the answer from @cmcginty. It was a great starting point for me, and much of what I'll post here borrowed heavily from it. However, the repos that I was moving have years of history which led to a few issues following that answer to the letter (hundreds of branches and tags that would need to be manually moved for one; read more later).
So after hours of searching and trial and error I was able to put together a script which allowed me to easily move several projects from SVN to GIT, and I've decided to share my findings here in case anyone else is in my shoes.
<tl;dr> Let's get started
First, create an 'Authors' file which will translate basic svn users to more complex git users. The easiest way to do this is using a command to extract all users from the svn repo you are going to move.
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
This will produce a file called authors-transform.txt with a line for each user that has made a change in the svn repo it was ran from.
someuser = someuser <someuser>
Update to include full name and email for git
someuser = Some User <[email protected]>
Now start the clone using your authors file
git svn clone --stdlayout --no-metadata -r854:HEAD --authors-file=authors-transform.txt https://somesvnserver/somerepo/ temp
This step can take awhile, particularly on a large or old repo (roughly 18 hours for one of ours). You can also use that -r switch to only take a small history to see the clone, and fetch the rest later.
Move to the new directory
cd temp
Fetch any missing history if you only pulled partial in clone
git svn fetch
Tags are created as branches during cloning. If you only have a few you can convert them one at a time.
git 1.0.0 origin/tags/1.0.0
However, this is tedious if you have hundreds of tags, so the following script worked for me.
for brname in `git branch -r | grep tags | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do echo $brname; tname=${brname:5}; echo $tname; git tag $tname origin/tags/$tname; done
You also need to checkout all branches you want to keep
git checkout -b branchname origin/branches/branchname
And if you have a lot of branches as well, this script may help
for brname in `git branch -r | grep -v master | grep -v HEAD | grep -v trunk | grep -v tags | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do echo $brname; git checkout -b $brname origin/$brname; done
This will ignore the trunk branch, as it will already be checked out as master and save a step later deleting the duplicate branch, as well as ignoring the /tags that we already converted.
Now is a good time to take a look at the new repo and make sure you have a local branch or tag for anything you want to keep as remote branches will be dropped in a moment.
Ok, now lets clone everything we've checked out to a clean repo (named temp2 here)
cd ..
git clone temp temp2
cd temp2
Now we'll need to checkout all of the branches one more time before pushing them to their final remote, so follow your favorite method from above.
If you're following gitflow you can rename your working branch to develop.
git checkout -b WORKING
git branch -m develop
git push origin --delete WORKING
git push origin -u develop
Now, if everything looks good, you're ready to push to your git repository
git remote set-url origin https://somebitbucketserver/somerepo.git
git push -u origin --all
git push origin --tags
I did run into one final issue which was that Control Freak initially blocked me from pushing tags that I didn't create, so if your team uses Control Freak you may need to disable or adjust that setting for your initial push.
Upvotes: 2
Reputation: 37774
Magic:
$ git svn clone http://svn/repo/here/trunk
Git and SVN operate very differently. You need to learn Git, and if you want to track changes from SVN upstream, you need to learn git-svn
. The git-svn
main page has a good examples section:
$ git svn --help
Upvotes: 553
Reputation: 95604
Cleanly Migrate Your Subversion Repository To a Git Repository. First you have to create a file that maps your Subversion commit author names to Git commiters, say ~/authors.txt
:
jmaddox = Jon Maddox <[email protected]>
bigpappa = Brian Biggs <[email protected]>
Then you can download the Subversion data into a Git repository:
mkdir repo && cd repo
git svn init http://subversion/repo --no-metadata
git config svn.authorsfile ~/authors.txt
git svn fetch
If you’re on a Mac, you can get git-svn
from MacPorts by installing git-core +svn
.
If your subversion repository is on the same machine as your desired git repository, then you can use this syntax for the init step, otherwise all the same:
git svn init file:///home/user/repoName --no-metadata
Upvotes: 207
Reputation: 830
I used the svn2git script and works like a charm.
Upvotes: 74
Reputation: 705
There is a new solution for smooth migration from Subversion to Git (or for using both simultaneously): SubGit.
I'm working on this project myself. We use SubGit in our repositories - some of my teammates use Git and some Subversion and so far it works very well.
To migrate from Subversion to Git with SubGit you need to run:
$ subgit install svn_repos
...
TRANSLATION SUCCESSFUL
After that you'll get Git repository in svn_repos/.git and may clone it, or just continue to use Subversion and this new Git repository together: SubGit will make sure that both are always kept in sync.
In case your Subversion repository contains multiple projects, then multiple Git repositories will be created in svn_repos/git directory. To customize translation before running it do the following:
$ subgit configure svn_repos
$ edit svn_repos/conf/subgit.conf (change mapping, add authors mapping, etc)
$ subgit install svn_repos
With SubGit you may migrate to pure Git (not git-svn) and start using it while still keeping Subversion as long as you need it (for your already configured build tools, for instance).
Hope this helps!
Upvotes: 34
Reputation: 16126
sudo apt-get install git-core git-svn ruby
sudo gem install svn2git
svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq > authors.txt (this command is for mapping the authors)
Above step should be performed in the folder that you are going to convert from svn to git.
Add one mapping per line in authors.txt like this
anand = Anand Tripathi <email_id>
trip = Tripathi Anand <email_id>
Create a folder for a new git repository and execute the command below having the path of authors.txt
svn2git <svn_repo_path> --nobranches --notags --notrunk --no-minimize-url --username <user_name> --verbose --authors <author.txt_path>
If no trunk and no tag and branch is present then have to execute the above command else if root is trunk then mention rootistrunk or trunk is present then --trunk <trunk_name>
git remote add origin
git push --all origin
git push --tags origin
Upvotes: -1
Reputation: 975
I´m on a windows machine and made a small Batch to transfer a SVN repo with history (but without branches) to a GIT repo by just calling
transfer.bat http://svn.my.address/svn/myrepo/trunk https://git.my.address/orga/myrepo
Perhaps anybody can use it. It creates a TMP-folder checks out the SVN repo there with git and adds the new origin and pushes it... and deletes the folder again.
@echo off
SET FROM=%1
SET TO=%2
SET TMP=tmp_%random%
echo from: %FROM%
echo to: %TO%
echo tmp: %TMP%
pause
git svn clone --no-metadata --authors-file=users.txt %FROM% %TMP%
cd %TMP%
git remote add origin %TO%
git push --set-upstream origin master
cd ..
echo delete %TMP% ...
pause
rmdir /s /q %TMP%
You still need the users.txt with your user-mappings like
User1 = User One <[email protected]>
Upvotes: 2
Reputation: 749
I used the following script to read a text file that has a list of all my SVN repositories and convert them to Git, and later use git clone --bare
to convert to a bare Git repository:
#!/bin/bash
file="list.txt"
while IFS= read -r repo_name
do
printf '%s\n' "$repo_name"
sudo git svn clone --shared --preserve-empty-dirs --authors-file=users.txt file:///programs/svn/$repo_name
sudo git clone --bare /programs/git/$repo_name $repo_name.git
sudo chown -R www-data:www-data $repo_name.git
sudo rm -rf $repo_name
done <"$file"
list.txt has the format:
repo1_name
repo2_name
And users.txt has the format:
(no author) = Prince Rogers <[email protected]>
www-data is the Apache web server user, and permission is needed to push changes over HTTP.
Upvotes: 0
Reputation: 585
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
Upvotes: 1
Reputation: 5250
We can use git svn clone
commands as below.
svn log -q <SVN_URL> | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt
Above command will create authors file from SVN commits.
svn log --stop-on-copy <SVN_URL>
Above command will give you first revision number when your SVN project got created.
git svn clone -r<SVN_REV_NO>:HEAD --no-minimize-url --stdlayout --no-metadata --authors-file authors.txt <SVN_URL>
Above command will create the Git repository in local.
Problem is that it won't convert branches and tags to push. You will have to do them manually. For example below for branches:
$ git remote add origin https://github.com/pankaj0323/JDProjects.git
$ git branch -a
* master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$$ git checkout -b MyDevBranch origin/MyDevBranch
Branch MyDevBranch set up to track remote branch MyDevBranch from origin.
Switched to a new branch 'MyDevBranch'
$ git branch -a
* MyDevBranch
master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$
For tags:
$git checkout origin/tags/MyDevBranch-1.0
Note: checking out 'origin/tags/MyDevBranch-1.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 3041d81... Creating a tag
$ git branch -a
* (detached from origin/tags/MyDevBranch-1.0)
MyDevBranch
master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$ git tag -a MyDevBranch-1.0 -m "creating tag"
$git tag
MyDevBranch-1.0
$
Now push master, branches and tags to remote git repository.
$ git push origin master MyDevBranch MyDevBranch-1.0
Counting objects: 14, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (14/14), 2.28 KiB | 0 bytes/s, done.
Total 14 (delta 3), reused 0 (delta 0)
To https://github.com/pankaj0323/JDProjects.git
* [new branch] master -> master
* [new branch] MyDevBranch -> MyDevBranch
* [new tag] MyDevBranch-1.0 -> MyDevBranch-1.0
$
svn2git utility removes manual efforts with branches and tags.
Install it using command sudo gem install svn2git
. After that run below command.
$ svn2git <SVN_URL> --authors authors.txt --revision <SVN_REV_NO>
Now you can list the branches, tags and push them easily.
$ git remote add origin https://github.com/pankaj0323/JDProjects.git
$ git branch -a
MyDevBranch
* master
remotes/svn/MyDevBranch
remotes/svn/trunk
$ git tag
MyDevBranch-1.0
$ git push origin master MyDevBranch MyDevBranch-1.0
Imagine you have 20 branches and tags, obviously svn2git will save you a lot of time and that's why I like it better than native commands. It's a nice wrapper around native git svn clone
command.
For a complete example, refer my blog entry.
Upvotes: 6
Reputation: 1
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 [email protected]:aUser/aProjectName.git
git push newrepo refs/heads/*
git push --tags newrepo
If you want more details, read my post or ask me.
Upvotes: 7
Reputation: 1317
There are different methods to achieve this goal. I've tried some of them and found really working one with just git and svn installed on Windows OS.
Prerequisites:
svnadmin dump /path/to/repository > repo_name.svn_dump
Steps to achieve final goal (move all repository with history to a git, firstly local git, then remote)
Create empty repository (using console tools or tortoiseSVN) in directory REPO_NAME_FOLDER
cd REPO_NAME_PARENT_FOLDER
, put dumpfile.dump into REPO_NAME_PARENT_FOLDER
svnadmin load REPO_NAME_FOLDER < dumpfile.dump
Wait for this operation, it may be long
This command is silent, so open second cmd window : svnserve -d -R --root REPO_NAME_FOLDER
Why not just use file:///...... ? Cause next command will fail with Unable to open ... to URL:
, thanks to the answer https://stackoverflow.com/a/6300968/4953065
Create new folder SOURCE_GIT_FOLDER
cd SOURCE_GIT_FOLDER
Finally, what do we got?
Lets check our Local repository :
git log
See your previous commits? If yes - okay
So now you have fully functional local git repository with your sources and old svn history. Now, if you want to move it to some server, use the following commands :
git remote add origin https://fullurlpathtoyourrepo/reponame.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags
In my case, I've dont need tags command cause my repo dont have tags.
Good luck!
Upvotes: 0
Reputation: 20246
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.
Upvotes: 0
Reputation: 25444
For complicated cases, reposurgeon by Eric S. Raymond is the tool of choice. In addition to SVN, it supports many other version control systems via the fast-export
format, and also CVS. The author reports successful conversions of ancient repositories such as Emacs and FreeBSD.
The tool apparently aims at near perfect conversion (such as converting SVN's svn:ignore
properties to .gitignore
files) even for difficult repository layouts with a long history. For many cases, other tools might be easier to use.
Before delving into the documentation of the reposurgeon
command line, be sure to read the excellent DVCS migration guide which goes over the conversion process step by step.
Upvotes: 13
Reputation: 1
GitHub has an importer. Once you've created the repository, you can import from an existing repository, via its URL. It will ask for your credentials if applicable and go from there.
As it's running it will find authors, and you can simply map them to users on GitHub.
I have used it for a few repositories now, and it's pretty accurate and much faster too! It took 10 minutes for a repository with ~4000 commits, and after it took my friend four days!
Upvotes: 0
Reputation: 115
Download the Ruby installer for Windows and install the latest version with it. Add Ruby executables to your path.
Then type “gem install svn2git” and enter
Migrate Subversion repository
Open a Ruby command prompt and go to the directory where the files are to be migrated
Then svn2git http://[domain name]/svn/ [repository root]
It may take few hours to migrate the project to Git depends on the project code size.
This major step helps in creating the Git repository structure as mentioned below.
SVN (/Project_components) trunk --> Git master SVN (/Project_components) branches --> Git branches SVN (/Project_components) tags --> Git tags
Create the remote repository and push the changes.
Upvotes: 0
Reputation: 777
Effectively using Git with Subversion is a gentle introduction to git-svn. For existing SVN repositories, git-svn makes this super easy. If you're starting a new repository, it's vastly easier to first create an empty SVN repository and then import using git-svn than it is going in the opposite direction. Creating a new Git repository then importing into SVN can be done, but it is a bit painful, especially if you're new to Git and hope to preserve the commit history.
Upvotes: 0
Reputation: 1
You have to Install
git
git-svn
Copied from this link http://john.albin.net/git/convert-subversion-to-git.
1. Retrieve a list of all Subversion committers
Subversion simply lists the username for each commit. Git’s commits have much richer data, but at its simplest, the commit author needs to have a name and email listed. By default the git-svn tool will just list the SVN username in both the author and email fields. But with a little bit of work, you can create a list of all SVN users and what their corresponding Git name and emails are. This list can be used by git-svn to transform plain svn usernames into proper Git committers.
From the root of your local Subversion checkout, run this command:
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
That will grab all the log messages, pluck out the usernames, eliminate any duplicate usernames, sort the usernames and place them into a “authors-transform.txt” file. Now edit each line in the file. For example, convert:
jwilkins = jwilkins <jwilkins>
into this:
jwilkins = John Albin Wilkins <[email protected]>
2. Clone the Subversion repository using git-svn
git svn clone [SVN repo URL] --no-metadata -A authors-transform.txt --stdlayout ~/temp
This will do the standard git-svn transformation (using the authors-transform.txt file you created in step 1) and place the git repository in the “~/temp” folder inside your home directory.
3. Convert svn:ignore properties to .gitignore
If your svn repo was using svn:ignore properties, you can easily convert this to a .gitignore file using:
cd ~/temp
git svn show-ignore > .gitignore
git add .gitignore
git commit -m 'Convert svn:ignore properties to .gitignore.'
4. Push repository to a bare git repository
First, create a bare repository and make its default branch match svn’s “trunk” branch name.
git init --bare ~/new-bare.git
cd ~/new-bare.git
git symbolic-ref HEAD refs/heads/trunk
Then push the temp repository to the new bare repository.
cd ~/temp
git remote add bare ~/new-bare.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare
You can now safely delete the ~/temp repository.
5. Rename “trunk” branch to “master”
Your main development branch will be named “trunk” which matches the name it was in Subversion. You’ll want to rename it to Git’s standard “master” branch using:
cd ~/new-bare.git
git branch -m trunk master
6. Clean up branches and tags
git-svn makes all of Subversions tags into very-short branches in Git of the form “tags/name”. You’ll want to convert all those branches into actual Git tags using:
cd ~/new-bare.git
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
git tag "$ref" "refs/heads/tags/$ref";
git branch -D "tags/$ref";
done
This step will take a bit of typing. :-) But, don’t worry; your unix shell will provide a > secondary prompt for the extra-long command that starts with git for-each-ref.
Upvotes: 8
Reputation: 5454
If you are using SourceTree you can do this directly from the app. Goto File -> New/Clone then do the following:
Open the repo in SourceTree and you'll see your commit messages have been migrated too.
Now go to Repository -> Repository Settings and add the new remote repo details. Delete the SVN remote if you wish (I did this through the "Edit Config File" option.
Push the code to the new remote repo when you are ready and code freely.
Upvotes: 3
Reputation: 1668
This guide on atlassian's website is one of the best I have found:
https://www.atlassian.com/git/migration
This tool - https://bitbucket.org/atlassian/svn-migration-scripts - is also really useful for generating your authors.txt among other things.
Upvotes: 8
Reputation: 5876
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!
Upvotes: 2
Reputation: 2668
A somewhat extended answer using just git, SVN, and bash. It includes steps for SVN repositories that do not use the conventional layout with a trunk/branches/tags directory layout (SVN does absolutely nothing to enforce this kind of layout).
First use this bash script to scan your SVN repo for the different people who contributed and to generate a template for a mapping file:
#!/usr/bin/env bash
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
echo "${author} = NAME <USER@DOMAIN>";
done
Use this to create an authors
file where you map svn usernames to usernames and email as set by your developers using git config
properties user.name
and user.email
(note that for a service like GitHub only having a matching email is enough).
Then have git svn
clone the svn repository to a git repository, telling it about the mapping:
git svn clone --authors-file=authors --stdlayout svn://example.org/Folder/projectroot
This can take incredibly long, since git svn will individually check out every revision for every tag or branch that exists. (note that tags in SVN are just really branches, so they end up as such in Git). You can speed this up by removing old tags and branches in SVN you don't need.
Running this on a server in the same network or on the same server can also really speed this up. Also, if for some reason this process gets interrupted you can resume it using
git svn rebase --continue
In a lot of cases you're done here. But if your SVN repo has an unconventional layout where you simply have a directory in SVN you want to put in a git branch you can do some extra steps.
The simplest is to just make a new SVN repo on your server that does follow convention and use svn copy
to put your directory in trunk or a branch. This might be the only way if your directory is all the way at the root of the repo, when I last tried this git svn
simply refused to do a checkout.
You can also do this using git. For git svn clone
simply use the directory you want to to put in a git branch.
After run
git branch --set-upstream master git-svn
git svn rebase
Note that this required Git 1.7 or higher.
Upvotes: 7
Reputation: 8798
TortoiseGit does this. see this blog post: http://jimmykeen.net/articles/03-nov-2012/how-migrate-from-svn-to-git-windows-using-tortoise-clients
Yeah, I know answering with links isn't splendid but it's a solution, eh?
Upvotes: 5
Reputation: 480
Pro Git 8.2 explains it: http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git
Upvotes: 14
Reputation: 3877
I just wanted to add my contribution to the Git community. I wrote a simple bash script which automates the full import. Unlike other migration tools, this tool relies on native git instead of jGit. This tool also supports repositories with a large revision history and or large blobs. It's available via github:
https://github.com/onepremise/SGMS
This script will convert projects stored in SVN with the following format:
/trunk
/Project1
/Project2
/branches
/Project1
/Project2
/tags
/Project1
/Project2
This scheme is also popular and supported as well:
/Project1
/trunk
/branches
/tags
/Project2
/trunk
/branches
/tags
Each project will get synchronized over by project name:
Ex: ./migration https://svnurl.com/basepath project1
If you wish to convert the full repo over, use the following syntax:
Ex: ./migration https://svnurl.com/basepath .
Upvotes: 2