I needed to convert several Subversion repositories to Git. Most of my process for this comes from this post. The following are some condensed steps and additional notes.
-
Work in a new
no-metadata
folder; this helps keep your working environment isolated, and will let you re-use theusers.txt
file if you need to do this to multiple repositories. Create theusers.txt
file and ensure all authors in the repo are listed. To get started, do something like this, whereSVN_URL
is the URL of the repo:svn log -q SVN_URL | awk -F " \\\\| " '/^r/ {print $2" = "$2" <>"}' | sort -u > users.txt
Note that this will preserve spaces in user names, if present (some other snippets you might find are broken and will not). Now edit
users.txt
and fill in details. You might need to add a(no author) = No Author <no@author.invalid>
line, too, if there are any commits which have no author, such as the empty ones created by some techniques that manipulate dump files to purge files. -
Use
git-svn
like this (replaceSVN_URL
with the correct URL) to clone the repo without metadata; add--stdlayout
if using standard branch folders, or as many-T
,-t
, and/or-b
options as necessary:git svn clone --no-metadata --authors-file=../users.txt SVN_URL
-
cd
into the new clone's folder. -
If necessary, change “master” branch to “main”:
git branch -m main
-
Purge history of bad commits, e.g., those by “(no author)”. Locate these manually, then perform an interactive rebase like so:
git rebase -i [SHA just prior to first bad commit]
Drop (
d
) the offending commits. -
Convert SVN “tags” branches to real git tags:
for t in `git branch -r | grep 'tags/' | sed s_tags/__` ; do git tag $t tags/$t^ git branch -d -r tags/$t done
-
Now it should be about ready to push to the new Git host:
git remote add origin GIT_URL git push -u origin main
-
Then make a fresh clone of
GIT_URL
. Done.
Comment to add? Send me a message: <brendon@quantumfurball.net>