Hari 29: Cara Mengimpor Proyek Subversion ke Repositori Git
Banyak organisasi masih menggunakan Subversion (SVN) tetapi ingin bermigrasi ke Git. Artikel ini menjelaskan cara mengimpor repositori SVN ke Git sambil mempertahankan riwayat.
Mengapa Bermigrasi dari SVN ke Git?
Keunggulan Git:
- Alur kerja terdistribusi
- Operasi lebih cepat (lokal)
- Branching dan merging yang lebih baik
- Bekerja secara offline
- Alur kerja yang lebih fleksibel
- Peralatan dan ekosistem yang lebih baik
Tantangan:
- Kurva pembelajaran
- Konsep yang berbeda
- Perubahan alur kerja
- Adaptasi tim
Strategi Migrasi
1. Impor Cepat (Sederhana)
Cepat tetapi kehilangan sebagian metadata SVN:
# Clone entire SVN repository
git svn clone http://svn.example.com/repo
# Or specify trunk/branches/tags structure
git svn clone http://svn.example.com/repo --trunk=trunk --branches=branches --tags=tags
2. Impor yang Tepat (Disarankan)
Mempertahankan penulis, branch, dan tag:
# Create authors file
# Map SVN users to Git users
echo "svnuser1 = John Doe <john@example.com>" >> authors.txt
echo "svnuser2 = Jane Smith <jane@example.com>" >> authors.txt
# Clone with authors file
git svn clone http://svn.example.com/repo \
--authors-file=authors.txt \
--trunk=trunk \
--branches=branches \
--tags=tags \
--no-metadata
3. Menggunakan svn2git (Paling Mudah)
Instal svn2git:
# On Mac
brew install svn2git
# On Linux
gem install svn2git
Buat file authors:
# Generate authors list from SVN
svn log -q http://svn.example.com/repo | \
awk -F '|' '/^r/ {print $2}' | \
sort -u > authors.txt
# Edit authors.txt to add email addresses
# Format: svnuser = Full Name <email@example.com>
Lakukan migrasi:
# Create new directory
mkdir git-repo
cd git-repo
# Run migration
svn2git http://svn.example.com/repo \
--authors authors.txt
Proses Migrasi Langkah demi Langkah
Fase 1: Persiapan
1. Identify SVN repository structure
2. Create authors mapping file
3. Decide on Git repository structure
4. Plan branch/tag strategy
5. Communicate with team
Fase 2: Uji Migrasi
# Do test migration first
git svn clone http://svn.example.com/repo test-migration
# Verify:
- Commit history
- Branches
- Tags
- File contents
Fase 3: Buat File Authors
Ekstrak penulis SVN:
svn log -q http://svn.example.com/repo | \
grep "^r" | \
awk '{print $3}' | \
sort -u > svn-authors.txt
Konversikan ke format Git:
# authors.txt
jdoe = John Doe <john.doe@example.com>
jsmith = Jane Smith <jane.smith@example.com>
admin = Administrator <admin@example.com>
Fase 4: Lakukan Migrasi
# Clone SVN repository
git svn clone http://svn.example.com/repo \
--authors-file=authors.txt \
--stdlayout \
migrated-repo
cd migrated-repo
# Convert SVN tags to Git tags
git for-each-ref refs/remotes/tags | cut -d / -f 4- | \
while read tagname; do
git tag "$tagname" "refs/remotes/tags/$tagname"
git branch -r -d "tags/$tagname"
done
# Convert SVN branches to Git branches
git for-each-ref refs/remotes/origin | cut -d / -f 4- | \
while read branchname; do
git branch "$branchname" "refs/remotes/origin/$branchname"
done
# Remove SVN remote
git remote rm origin
Fase 5: Push ke Remote Git
# Add Git remote
git remote add origin https://github.com/your-org/repo.git
# Push all branches
git push -u origin --all
# Push all tags
git push -u origin --tags
Menangani Kasus Khusus
Repositori Besar
Untuk repositori besar, impor secara bertahap:
# Start from revision 1000
git svn clone http://svn.example.com/repo \
-r 1000:HEAD \
--authors-file=authors.txt
Mengabaikan Path
Buat .gitignore berdasarkan pengabaian SVN:
# Extract SVN ignores
git svn show-ignore > .gitignore
# Commit
git add .gitignore
git commit -m "Add .gitignore from SVN"
File Biner
SVN dan Git menangani biner secara berbeda:
# For large binary files, consider Git LFS
git lfs install
git lfs track "*.psd"
git lfs track "*.zip"
Jembatan SVN (git-svn)
Terus gunakan SVN sambil bertransisi:
# Clone with git-svn
git svn clone http://svn.example.com/repo
# Work normally with Git locally
# Get SVN updates
git svn rebase
# Push to SVN
git svn dcommit
Alur Kerja:
# Pull from SVN
git svn rebase
# Make changes
git add .
git commit -m "Changes"
# Push to SVN
git svn dcommit
Tugas Setelah Migrasi
1. Verifikasi Migrasi
# Check commit count
git log --oneline | wc -l
# Compare with SVN
# Should match or be close
# Check specific files
git log -- path/to/file.txt
svn log path/to/file.txt
# Verify branches
git branch -a
# Verify tags
git tag
2. Perbarui CI/CD
- Perbarui skrip build
- Ubah URL VCS
- Perbarui pipeline deployment
- Uji semua proses otomatis
3. Latih Tim
- Lokakarya dasar-dasar Git
- Dokumentasi alur kerja baru
- Praktik langsung
- Dukungan selama transisi
4. Perbarui Dokumentasi
- Perbarui README
- Ubah petunjuk checkout
- Perbarui panduan kontribusi
- Dokumentasikan alur kerja baru
Perbandingan: Perintah SVN vs Git
# Checkout
SVN: svn checkout
Git: git clone
# Update
SVN: svn update
Git: git pull
# Commit
SVN: svn commit
Git: git commit + git push
# Status
SVN: svn status
Git: git status
# Log
SVN: svn log
Git: git log
# Branch
SVN: svn copy .../trunk .../branches/name
Git: git checkout -b name
# Tag
SVN: svn copy .../trunk .../tags/v1.0
Git: git tag v1.0
# Merge
SVN: svn merge
Git: git merge
# Diff
SVN: svn diff
Git: git diff
Pemecahan Masalah
Masalah: Commit yang Hilang
# Check SVN revision range
git svn log | head -n 20
# Re-clone from specific revision
git svn clone -r START:HEAD ...
Masalah: Kesalahan Pemetaan Penulis
# Add missing authors to authors.txt
# Re-run migration
Masalah: Direktori .git yang Besar
# Garbage collection
git gc --aggressive --prune=now
# Consider shallow clone for very old history
Ringkasan Hari Ini
Bermigrasi dari SVN ke Git memerlukan perencanaan dan eksekusi yang hati-hati. Menggunakan alat yang tepat seperti svn2git dan mempertahankan pemetaan penulis memastikan transisi yang lancar. Luangkan waktu untuk menguji migrasi, memverifikasi hasil, dan melatih tim Anda tentang alur kerja Git.
Izinkan saya menyusun kembali perintah dan parameter Git yang dipelajari hari ini:
- git svn clone
- git svn rebase
- git svn dcommit
- git svn show-ignore
- git for-each-ref
- git gc –aggressive
- Kembali ke Daftar Isi
- Hari Sebelumnya: Memahami Alur Kerja Fork dan Pull Request di GitHub
- Hari Berikutnya: Berbagi Tips Operasi Git yang Berguna dari Pekerjaan