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
Citations & Further Reading
- git-scm.com — Git svn [Official]
- Git and Other Systems Migrating to Git [Book]
What you will learn
- Understand the core purpose of SVN to Git Migration Guide
- Master the basic usage and common options of 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.
- Understand key concepts: Before Migration
- Know when to use this feature and when to avoid it
Start with a problem
Your team is migrating from another version control system to Git, or moving code and history between different Git platforms. You're worried about losing commit history or author information during the process.
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 |
Try it yourself
- Practice the svn-to-git command in a test repository and observe state changes before and after
- Experiment with different options and compare the output differences
- Simulate a real scenario where you would need to use this, and walk through the full process
Continue Learning
learning-path/quick-start— Git quick startworkflows/feature-branch-collaboration— Feature branch workflowbest-practices/commit-hygiene— Commit conventions
Further reading
Keep going on the same topic:
Previous / Next
PreviousNo more reads in this direction
NextMercurial to Git Migration GuideCommands