SVN to Git Migration: Fix Common Problems
In this article
Migrating a firmware project from SVN to Git often hits snags like missing binary history, broken line endings, or submodule confusion. This guide walks you through the most common migration problems and how to fix them, so you end up with a clean, usable Git repository.
What You'll Need
- A local SVN checkout or access to the SVN repository (read access is enough).
- Git installed (version 2.x or newer recommended).
git-svn(included with most Git distributions).- Optional:
svncommand-line client for verification. - Backup of the original SVN repository (or at least a full dump) before starting.
Step-by-Step
- Create a local SVN mirror (optional but recommended). Use
svnadmin dumpandsvnadmin loadto create a local copy. This avoids network issues and lets you test repeatedly. - Generate an authors file. Run
svn log --xmlto extract usernames, then map each to a Git identity (e.g.,jdoe = John Doe <john@example.com>). Save asauthors.txt. - Clone with git-svn. Run
git svn clone --authors-file=authors.txt --trunk=trunk --branches=branches --tags=tags <svn-url> firmware-git. For a standard layout, you can omit the--trunk/--branches/--tagsflags if the layout is conventional. - Convert SVN tags to Git tags. After cloning, run
git svn tag(or manually create tags from therefs/remotes/origin/tags/*branches). Delete the temporary remote branches that represent tags. - Clean up branches. Rename remote branches to local branches with
git branch -randgit branch -t, or simply create local branches from the remote-tracking ones. - Fix line endings. Add a
.gitattributesfile to enforce consistent line endings (e.g.,* text=autoand specific patterns for binary files like*.bin binary). Rungit add --renormalize .to apply. - Handle large binaries. If your firmware has large binary blobs (e.g., compiled hex files), consider using Git LFS. Run
git lfs track "*.hex"and thengit add .gitattributesand re-commit the binaries. - Verify history integrity. Compare the number of commits in SVN and Git (
svn log --stop-on-copyvsgit rev-list --count HEAD). Spot-check a few commit messages and file changes. - Push to a remote Git server. Once satisfied, add a remote and push all branches and tags:
git push origin --allandgit push origin --tags.
Common Mistakes
- Forgetting the authors file. Without it, git-svn uses the SVN username as the Git author, which is fine but not ideal for long-term attribution.
- Ignoring binary files. Firmware projects often contain compiled artifacts. If you don't handle them, the repo becomes bloated and slow.
- Not cleaning up SVN refs. Leftover remote branches like
refs/remotes/origin/trunkcan confuse future users. - Assuming SVN tags become Git tags automatically. They don't; they come over as branches unless you convert them.
- Overlooking line endings. Mixed line endings cause spurious diffs and merge conflicts.
Tips
- Test the migration on a throwaway clone first. If something goes wrong, you haven't touched your real data.
- Use
--no-metadatain git-svn if you don't need the SVN revision numbers in commit messages (keeps history cleaner). - If the SVN repo is huge, consider migrating only the trunk and recent history, but be aware you lose older history.
- After migration, run
git fsckto check for repository corruption. - Document the migration steps and any manual fixes you made; future maintainers will thank you.
Troubleshooting
- git-svn clone fails with "Unable to determine upstream SVN information". This usually means the SVN layout isn't standard. Use explicit
--trunk,--branches, and--tagsflags pointing to the correct paths. - Missing commits or branches. Check if the SVN repo uses copy operations that git-svn didn't follow. You may need to manually fetch specific revisions with
git svn fetch -r <revision>. - Binary files are corrupted after migration. This often happens due to text conversion. Ensure your
.gitattributesmarks binary extensions asbinary, and re-commit the files after fixing the attributes. - Line endings show as changed when there were no changes. This is a classic symptom of missing
.gitattributes. Add it and renormalize. - Tags are empty or point to wrong commits. SVN tags are often copies of branches; git-svn may not preserve the original tag commit. Manually recreate tags from the correct commit hashes.
- Performance is slow during clone. Use
--preserve-merges? Actually, for SVN,--preserve-mergesis not applicable. Instead, try--no-minimize-urlor increase--fetch-allif branches are many.
Frequently Asked Questions
Can I migrate without git-svn?
Yes, tools like svn2git (Ruby) or svn-all-fast-export (KDE) can be more efficient, but git-svn is the most widely available and works well for most projects.
What if my SVN repo has no standard trunk/branches/tags layout?
You can still migrate by specifying the exact paths in git-svn options. For example, use --trunk=/project/trunk and so on. If the layout is flat, you can treat the whole repo as trunk.
Will SVN revision numbers be preserved?
By default, git-svn appends a line like git-svn-id: ...@revision to commit messages, which preserves the revision number. If you use --no-metadata, that line is omitted, but you lose the direct mapping.
How do I handle SVN externals?
SVN externals do not have a direct Git equivalent. You'll need to either vendor the external code into your repo (as a subdirectory) or use Git submodules. Submodules add complexity; vendoring is simpler for firmware projects.
What about large binary files like compiled firmware images?
Use Git LFS. It stores a pointer in Git and the actual binary in a separate storage. This keeps your repo lightweight and avoids bloating history.
Can I keep the old SVN history after migration?
Yes, the entire history is preserved in the Git repository. You can even keep the SVN repo as a read-only archive, but all development should move to Git.