Svn2git

Aus SDQ-Wiki
Zur Navigation springen Zur Suche springen

To migrate some folders of an svn repository with all commit history to a git repository, you can do the following:

First, you have to go to the folder that you like to migrate and extract all authors :

svn log --xml | grep -P "^<author" | sort -u | perl -pe 's/<author>(.*?)<\/author>/$1 = /' > authors.txt

Source: http://thomas-cokelaer.info/blog/2014/08/migrating-from-a-subversion-repository-to-github/

This file has to have the following format:

svnuser1 = Firstname Surname <email>

If you are not sure about these personal details you can use the public github API to find out: https://www.eremedia.com/sourcecon/how-to-find-almost-any-github-users-email-address/

The authors file which was used to migrate SimuLizar can be found in the SDQ-SVN (https://svnserver.informatik.kit.edu/i43/svn/code/GitMigration/authors.txt). Additional mappings should be inserted there to facilitate future migrations. If you do not possess the access rights to append new mappings to the authors file, please contact one of the members of SDQ.

Then, you have to use the command "git svn clone" to clone a new git repo from the svn subfolder:

git svn clone reporul --authors-file=/localpath/to/authors.txt --trunk=trunk/directory --branches=branches/*/directory --tags=tags/*/directory NewGitRepoNameForSubfolder

Source: http://thomas-cokelaer.info/blog/2014/11/migrating-a-svn-sub-directory-to-github/ and http://thomas-cokelaer.info/blog/2014/08/migrating-from-a-subversion-repository-to-github/

From this subfolder you can extract folders to new git repositories. First, create a branch using "git subtree split":

git subtree split -P OldSVNSubFolder/SubSubFolder -b nameForNewBranch 

Then create and initialize a new bare repository:

git init --bare ../NewSubRepoBARE

Make the bare repository for the subtree known to the initial repository:

git remote add newsubrepo ../NewSubRepoBARE

Push the branch for the subtree to the bare repository:

git push nameForNewBranch newsubrepo:master

Source: https://coderwall.com/p/a3a5xg/splitting-a-project-sub-directory-to-a-new-git-repo

You can clone the bare repository to change stuff (and then commit and push it to the bare one):

git clone ../NewSubRepoBARE/ ../NewSubRepo

Finally, push the bare repository to github:

git push --mirror https://github.com/your-github-user/thegithubreponame

Source: https://help.github.com/articles/importing-a-git-repository-using-the-command-line/

That's it!

If you have to migrate a lot of svn folders to GIT you can try to adapt this bash script called "subtreegit":

OLDREPO=$1;
BUNDLEPARENTFOLDERPATH=$2;
BUNDLENAME=$3;
TREENAME=$4;
NEWREPO=$5;
NEWBAREREPO=$5BARE;

echo "subtreegit start";
cd $OLDREPO;
git subtree split -P $BUNDLEPARENTFOLDERPATH$BUNDLENAME -b $TREENAME;
echo "splitted $BUNDLENAME in $BUNDLEPARENTFOLDERPATH of $OLDREPO to new tree $TREENAME";
git init --bare ../$NEWBAREREPO;
git remote add $TREENAME ../$NEWBAREREPO;
git push $TREENAME $TREENAME:master;
git clone ../$NEWBAREREPO/ ../$NEWREPO;
cd ..;
echo "subtreegit done";

If you migrate a lot of Eclipse plug-in projects from svn to separate GIT repositories, then you might find this bash script useful:

OLDREPO=$1;
BUNDLEPARENTFOLDERPATH=$2;
BUNDLENAME=$3;
TREENAME=$4;
NEWREPO=$5;
NEWBAREREPO=$5BARE;

echo "subtreebundlegit start";
subtreegit $1 $2 $3 $4 $5;
cd $NEWREPO;
mkdir -p bundles/$BUNDLENAME;
git mv META-INF/ bundles/$BUNDLENAME/;
git mv src bundles/$BUNDLENAME/;
git mv build.properties bundles/$BUNDLENAME/;
git mv .classpath bundles/$BUNDLENAME/;
git mv .project bundles/$BUNDLENAME/;
git mv .settings bundles/$BUNDLENAME/;
git commit -m "moved bundle content to new bundle folder";
git push;
cd ..;
echo "subtreebundlegit done";