Migrate SVN to GIT with history
I was recently working on SVN to Git migration project, Just sharing a high-level process might be useful for anyone for the SVN to Git migration process.
There are many tools such as svn2git, git-svn, and SubGit, etc…
Initially tried with git-svn but faced issues with huge bigger and old history projects. Later used svn2git, its works like a charm!.
I personally highly recommend the svn2git tool for migration. SVN2GIT is a good choice for the huge repositories.
I’m unable to find any straightforward and best article, just writing using git2svn tool, available many techniques including git-svn, but I personally and strongly recommend svn2git for the huge and old history projects!. And here we will discuss the migration SVN to Git migration project using the svn2git tool.
- Installation svn2git
Windows:
Go get it from the Ruby Installer for Windows page and install the latest version.
Install the svn2git gem
gem install svn2git
Linux:
Install git, git-svn, and ruby
$ sudo apt-get install git-core git-svn ruby
Install the svn2git gem
$ sudo gem install svn2git
2. SVN Repo List
svn list http://[your domain name]/svn/[your repository trunk root]
3. Retrieve a list of all Subversion authors
Windows:
svn log http://[your domain name]/svn/[your repository trunk root] --quiet | ? { $_ -notlike '-*' } | % { "{0} = {0} <{0}>" -f ($_ -split ' \| ')[1] } | Select-Object -Unique | Out-File 'authors.txt'
Linux:
svn log http://[your domain name]/svn/[your repository trunk root] --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq |tee -a authors.txt
You can then edit authors.txt each line in the file to create a mapping of SVN users to a well-formatted Git user. For example, you can map rajaramtt = rajaramtt <rajaramtt>
to rajaramtt = Raja Rama Mohan T <rajaram.tavalam@gmail.com>
.
4. Clone the Subversion repository using git-svn
svn2git http://[your domain name]/svn/[your repository trunk root] — trunk / — nobranches — notags — authors authors.txt
5. Find empty directories and add .gitignore
Windows Powershell
Get-ChildItem -Directory -Recurse | Where-Object -FilterScript {($_.GetFiles().Count -eq 0) -and $_.GetDirectories().Count -eq 0} | Select-Object -ExpandProperty FullName
Linux Terminal
find . -type d -empty
Add Git ignore
git svn show-ignore > .gitignore
Git doesn’t track empty directories, Please add the .gitkeep file in the above empty directories, add and commit.
git add [your empty directories files and git ignore]
git commit -m '[your commit message]'
6. Push repository
git remote add origin http://[your git repo URL.git]git push origin — mirror
7. Sync your svn repo to bitbucket
svn2git --rebasegit push origin master
Credits:
Follow Me for the latest updates.
Medium: @rajaramtt