Migration SVN vers Git
J’utilise de plus en plus Git en lieu et place de SVN et pour ce faire j’ai du migrer plusieurs de mes projets. Voici la marche à suivre que j’utilise :
Créer un répertoire de travail :
cd ~
mkdir GitMigration
cd gitMigration
Créer un fichier « users.txt » afin de convertir les utilisateurs SVN vers Git :
vi users.txt
# yann = Yann Lugrin
# dhh = David Heinemeier Hansson
# ...
#
Cloner le dépôt SVN (ce code part du principe que vous respecter la convention trunk/branches/tags dans SVN, si vous utiliser des nom différents ou simplement avec des majuscule, adapter la première ligne de code) :
git svn clone --prefix=svn/ --no-metadata -A ~/GitMigration/users.txt -T trunk -b branches -t tags http://URL-TO/SVN/PROJECT-NAME PROJECT-NAME
cd PROJECT-NAME
git reset --hard svn/trunk
Vérifier la liste des branches :
git branch -r
# origin/master
# svn/trunk
# svn/your-first-branch
# svn/another-branch
# svn/tags/your-first-tag
Faire un checkout des branches :
git checkout -b YOUR-FIRST-BRANCH YOUR-FIRST-BRANCH
git checkout -b YOUR-SECOND-BRANCH YOUR-SECOND-BRANCH
Puis créer les tags (il faut créer une branche depuis le tag SVN, la tagger, puis détruire la branche) :
git checkout -b tags/YOUR-FIRST-TAG tags/YOUR-FIRST-TAG
git tag tags/YOUR-FIRST-TAG
git checkout -b tags/YOUR-SECOND-TAG tags/YOUR-SECOND-TAG
git tag tags/YOUR-SECOND-TAG
git checkout master
git branch -D tags/YOUR-FIRST-TAG
git branch -D tags/YOUR-SECOND-TAG
Voilà la migration est complète, vous pouvez maintenant ajouter un remote (GitHub par exemple) et y faire un push (sans oublier les tags) :
git remote add origin git@github.com:GITHUB_USERNAME/REPO_NAME.git
git push --all
git push --tags
