Lo que lograrás
Convertirás un repositorio SVN a Git, preservando autores, fechas, branches y tags, y pushearás el resultado a un host Git.
Paso 1: preparar
svn info https://svn.example.com/repo
svn ls https://svn.example.com/repo
Paso 2: construir mapeo de autores
svn log --xml https://svn.example.com/repo \
| grep -E '<author>' \
| sort -u \
| sed -E 's/.*>(.+)<.*/\1 = \1 <\[email protected]>/' \
> authors.txt
jdoe = Jane Doe <[email protected]>
bsmith = Bob Smith <[email protected]>
Paso 3: convertir con git svn
git svn clone \
--stdlayout \
--authors-file=authors.txt \
https://svn.example.com/repo \
repo.git
cd repo.git
Paso 4: convertir tags SVN a tags Git
git for-each-ref refs/remotes/origin/tags --format='%(refname:short)' \
| while read ref; do
tag="${ref#origin/tags/}"
git tag "$tag" "$ref"
git update-ref -d "refs/remotes/$ref"
done
Paso 5: convertir branches SVN a branches Git
git for-each-ref refs/remotes/origin --format='%(refname:short)' \
| grep -v '^origin/tags' \
| while read ref; do
branch="${ref#origin/}"
if [ "$branch" != "trunk" ]; then
git branch "$branch" "$ref"
fi
git update-ref -d "refs/remotes/$ref"
done
Paso 6: renombrar trunk a main
git branch -m trunk main
Paso 7: verificar
git log --oneline | wc -l
svn log -q https://svn.example.com/repo | grep -c '^r'
git tag | wc -l
git branch | wc -l
Paso 8: pushear a un host Git
git remote add origin [email protected]:myorg/repo.git
git push -u origin --all
git push origin --tags
Paso 9: manejar externals
- Vendor.
- Submódulos.
- Gestor de paquetes.
Paso 10: manejar contenido grande o binario
git filter-repo --strip-blobs-bigger-than 50M
git lfs migrate import --include="*.psd,*.zip" --everything
Paso 11: comunicar el cutover
Paso 12: mantener SVN solo lectura
Trampas comunes
- Archivo de autores incompleto.
- Layout no estándar.
- Tracking de merges SVN.
- Directorios vacíos.