{"id":2292,"date":"2012-06-20T15:23:53","date_gmt":"2012-06-20T13:23:53","guid":{"rendered":"http:\/\/blog.unelink.es\/?p=2292"},"modified":"2012-06-14T11:30:32","modified_gmt":"2012-06-14T09:30:32","slug":"migrar-de-subversion-a-git","status":"publish","type":"post","link":"https:\/\/hosting.airetech.es\/blog\/wiki\/migrar-de-subversion-a-git\/","title":{"rendered":"Migrar de subversion a GIT"},"content":{"rendered":"<p>En la migraci\u00f3n que vamos a realizar, mantendremos tanto los logs como todos sus branches y tags desde un SCV a otro.<\/p>\n<p>Para poder seguir este manual necesitaremos un paquete llamado<\/p>\n<pre>\r\ngit-svn\r\n<\/pre>\n<p>el cual, seg\u00fan la distribuci\u00f3n que usemos, se har\u00e1 de un modo u otro<\/p>\n<p>Ubuntu, Debian y derivados<\/p>\n<pre>\r\napt-get install git-svn\r\n<\/pre>\n<p>CentOS y derivados<\/p>\n<pre>\r\nyum install git-svn\r\n<\/pre>\n<p>1. Creaci\u00f3n del repositorio GIT de destino<\/p>\n<p>Para crear el repositorio GIT hacemos uso de un peque\u00f1o script que donde se le pasa como \u00fanico par\u00e1metro el nombre del repositorio:<\/p>\n<pre name=\"code\" class=\"java\">\r\nsh makegit.sh mirepo\r\n<\/pre>\n<p>En este script debes de modificar la definici\u00f3n de las constantes de las primeras l\u00edneas para ajustarlo a tu entorno<\/p>\n<pre name=\"code\" class=\"java\">\r\n#!\/bin\/sh\r\n\r\nGIT_OWNER=\"__NOMBRE__PROPIETARIO__\"\r\nGIT_EMAIL=\"__EMAIL_PROPIETARIO__\"\r\nGIT_HOME=\"__RUTA_COMPLETA_DIRECTORIO_GIT__\"\r\nGIT_REPO=$1\".git\"\r\n\r\ncd ${GIT_HOME}\r\nmkdir ${GIT_REPO}\r\ncd ${GIT_REPO}\r\n\r\ngit init --bare\r\ngit config --global user.name ${GIT_OWNER}\r\ngit config --global user.email ${GIT_EMAIL}\r\ngit repo-config core.sharedRepository true\r\n\r\ncd ${GIT_HOME}\r\nchown -R git:git ${GIT_REPO}\r\nchmod -R 775 ${GIT_REPO}\r\nchmod -R g+ws ${GIT_REPO}\r\nchgrp -R git ${GIT_REPO}\r\n<\/pre>\n<p>Lo ejecutamos y creamos el nuevo repositorio GIT.<\/p>\n<p>2. Creamos repositorio GIT vac\u00edo<\/p>\n<p>Este repositorio es donde vamos a volcar y transformar todos los datos desde el subversion<\/p>\n<pre>\r\ncd \/tmp\/\r\ngit svn init -s https:\/\/svn.miservidor.com\/mirepo migracion\r\ncd migracion\r\n<\/pre>\n<p>3. Usuarios remotos subversion<\/p>\n<p>El siguiente paso es crear un fichero donde vamos a ir poniendo los usuarios subversion, para poder tener la relaci\u00f3n de los logs correctamente.<\/p>\n<p>Este fichero tiene el siguiente formato, no debiendo omitir ning\u00fan dato<\/p>\n<pre>\r\nnombre_usuario_1 = Nombre del Usuario 1 &lt;mail1@usuario.com&gt;\r\nnombre_usuario_2 = Nombre del Usuario 2 &lt;mail2@usuario.com&gt;\r\n<\/pre>\n<p>lo guardamos en el fichero<\/p>\n<pre>\r\nusuarios\r\n<\/pre>\n<p>y ejecutamos<\/p>\n<pre name=\"code\" class=\"java\">\r\ngit config svn.authorsfile usuarios\r\ngit svn fetch\r\ngit branch -r | sed -rne 's, *tags\/([^@]+)$,\\1,p' | while read tag; do echo \"git tag $tag 'tags\/${tag}^'; git branch -r -d tags\/$tag\"; done | sh\r\ngit branch -r | grep -v tags | sed -rne 's, *([^@]+)$,\\1,p' | while read branch; do echo \"git branch $branch $branch\"; done | sh\r\n<\/pre>\n<p>compactamos el repositorio y quitamos la metadata del subversion<\/p>\n<pre>\r\ngit repack -d -f -a --depth=50 --window=100\r\ngit config --remove-section svn-remote.svn\r\ngit config --remove-section svn\r\nrm -r .git\/svn\r\n<\/pre>\n<p>Para poder sacar la lista completa de usuarios subversion desde la misma m\u00e1quina donde tenemos el repositorio de subversion, podemos ejecutar<\/p>\n<pre>\r\nsvn log -q https:\/\/svn.miservidor.com\/mirepo | grep -e '^r' | awk 'BEGIN {FS=\"|\"};{print $2}'|sort|uniq\r\n<\/pre>\n<p>y veremos la lista de todos los usuarios que necesitamos crear en GIT para mantener el log completo y correcto.<\/p>\n<p>4. Integraci\u00f3n en GIT<\/p>\n<p>Una vez tenemos el repositorio de subversion pasado a GIT, bastar\u00e1 con asociar el origen y hacer el \"push\"<\/p>\n<pre>\r\ncd \/tmp\/migracion\r\ngit remote add origin git@miservidor.com:mirepo.git\r\ngit push --all && git push --tags\r\n<\/pre>\n<p>y con esto ya tenemos migrado nuestro repositorio subversion a nuestro servidor GIT, y sin perder el hist\u00f3rico.<\/p>\n","protected":false},"excerpt":{"rendered":"En la migraci\u00f3n que vamos a realizar, mantendremos tanto los logs como todos sus branches y tags desde un SCV a otro. Para poder seguir este manual necesitaremos un paquete llamado git-svn el cual, seg\u00fan la distribuci\u00f3n que usemos, se har\u00e1 de un modo u otro Ubuntu, Debian y derivados apt-get install git-svn CentOS y derivados yum install git-svn 1.&nbsp;<a href=\"https:\/\/hosting.airetech.es\/blog\/wiki\/migrar-de-subversion-a-git\/\" class=\"read-more\">Seguir leyendo<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10,6],"tags":[156,216,168,111],"class_list":["post-2292","post","type-post","status-publish","format-standard","hentry","category-linux","category-wiki","tag-git","tag-linux","tag-migrar","tag-subversion","cat-10-id","cat-6-id"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/comments?post=2292"}],"version-history":[{"count":6,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2292\/revisions"}],"predecessor-version":[{"id":2341,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2292\/revisions\/2341"}],"wp:attachment":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/media?parent=2292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/categories?post=2292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/tags?post=2292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}