Migration
SVN to Git Migration Guide
A complete guide to migrating from Subversion (SVN) to Git, covering history conversion, branch mapping, team training, and common pitfalls.
- Teams migrating from SVN or Hg to Git
- Basic knowledge of SVN or Hg operations
- Basic Git experience
- Author information lost or mis-mapped after migration
- Large files not handled, causing repository bloat after migration
One-Sentence Understanding
Migrating from SVN to Git is not just copying code — it's shifting from "centralized file versioning" to "distributed snapshot engine" thinking.
Before Migration
Assess the SVN Repo
svn log -q --limit 1
svn ls ^/
# Confirm standard layout
svn ls ^/trunk
svn ls ^/branches
svn ls ^/tags
Prepare Author Mapping
Create authors.txt:
svn_username = Full Name <email@example.com>
jdoe = John Doe <john@example.com>
Tool Selection
| Tool | Best For | Notes |
|---|---|---|
git svn clone | Small to medium repos | Built-in, reliable |
svn2git | More control | Wrapper around git svn |
svn-all-fast-export | Very large repos | Best performance (KDE project) |
Migrate with git svn
Step 1: Clone
git svn clone http://svn.example.com/project \
--stdlayout \
--authors-file=authors.txt \
--prefix=svn/ \
project-git
cd project-git
Step 2: Clean Up Tags
git for-each-ref --format='%(refname)' refs/remotes/svn/tags/ |
while read tag; do
tag_name=${tag#refs/remotes/svn/tags/}
git tag "$tag_name" "$tag^{}"
git branch -r -d "svn/tags/$tag_name"
done
Step 3: Map Branches
git for-each-ref --format='%(refname)' refs/remotes/svn/ |
grep -v 'svn/tags' |
while read branch; do
branch_name=${branch#refs/remotes/svn/}
git branch "$branch_name" "$branch"
git branch -r -d "svn/$branch_name"
done
Step 4: Push to Remote
git remote add origin git@github.com:user/project.git
git push origin --all
git push origin --tags
Common Issues
Large Files
# Find large files
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectsize) %(rest)' | sort -k2 -n -r | head -20
# Clean with BFG
java -jar bfg.jar --strip-blobs-bigger-than 100M project.git
Empty Directories
find . -type d -empty -not -path "./.git/*" -exec touch {}/.gitkeep \;
Binary Files
Use Git LFS:
git lfs install
git lfs track "*.dll"
git lfs migrate import --include="*.dll,*.exe" --everything
Team Migration Plan
Phase 1: Assessment
- Evaluate SVN repo (history, size, branches)
- Prepare author mapping
- Choose migration tool
- Trial migration off-hours
Phase 2: Pilot
- Small team tests Git
- Collect feedback
- Improve documentation
Phase 3: Switchover
- Freeze SVN
- Final migration
- Verify results
- Full team switch
Phase 4: Transition
- SVN read-only (1-3 months)
- Train team on Git workflows
- Archive SVN repo
Mindset Comparison
| Dimension | SVN | Git |
|---|---|---|
| Model | Centralized file versioning | Distributed snapshots |
| Branches | Directory copies (slow, heavy) | Pointers (fast, light) |
| Commits | Global sequential numbers | SHA hashes |
| History | Linear | DAG |
| Offline | Unavailable | Full functionality |
Continue Learning
learning-path/quick-start— Git quick startworkflows/feature-branch-collaboration— Feature branch workflowbest-practices/commit-hygiene— Commit conventions
Previous / Next
PreviousNo more reads in this direction
NextMercurial to Git Migration GuideCommands