From SVN repository to Git repository

Hoca Chen
2 min readJun 5, 2022
Photo by Yancy Min on Unsplash

Recently, we start moving our repository from SVN to Git in order to get the benefit of Git. This article recodes the step that I did and hopes it can help readers who need the same stuff as me.

  • Name list of SVN

In the first step, we need to prepare the list file that has all the activation of SVN authors.

Using the command tool such ad “command prompt” or “PowerShell” in windows.

Navigate the working directory to the “SVN working” folder, then send the Git command line: (Please install Git first, https://git-scm.com/)

svn.exe log — quiet | ? { $_ -notlike ‘-*’ } | % { “{0} = {0} <{0}>” -f ($_ -split ‘ \| ‘)[1] } | Select-Object -Unique

in the author file, the authors mapping list needs manually modify the mail address.

e.g. john.lee = john.lee <john.lee> to john.lee = john.lee <john.lee@mail.com>

after done, the format of the author file must be “UTF-8”. Notepad++ is a tool to employ the file.

  • Dump file from SVN to Git Format

Create a new folder for Git and copy the author list file to this directory.

Navigate the new Git folder directory and execute the Git command via the command tool:

git svn clone [http://svn_root/your_repo] — no-minimize-url -A [author_list.txt] [c:\YourGitFolder]

Now it is starting to dump the file from SVN and its commit list to Git format.

If you want to dump everything of SVN, you can give the “svn root” in the address above. If you only want to dump the specific repo for instance some branch, you can just give the “svn_root/your_repo/branch/xxx”.

  • Clean up your Git repo(Option)

If you finish download the repo that you need, you can do the clean job for it. This is different compare with SVN.

What I used is tool BFG (https://rtyley.github.io/bfg-repo-cleaner/). This tool can help you to clean the file that you do not want before push to your server.

  1. download the bfg.jar and placing the file to your new Git directory.
  2. Commnad for instance clean all file bigger than 5MB.

java -jar bfg-1.14.0.jar — strip-blobs-bigger-than 5M xxxx.git

3. Forced it to clean file

git reflog expire — expire=now — all

git gc — prune=now — aggressive

Note: it may clean some file that your project needs, please carefully.

  • Ready for Push it to server

The finial step is give the Git origin then Push it

git remote add origin [URL]

git push origin — all

Done

Hope this article can help you if you are looking the same information as me.

--

--