April 9, 2020
Estimated Post Reading Time ~

Migrating Code Base from SVN to GIT

I have a use case where I need to migrate the codebase from svn to git while preserving all the commits of different committers.
For migration, I have used a utility tool git-svn.
In order to install git-svn we can use below command in Linux box : sudo apt-get install git-svn

After that, you can follow the steps mentioned below to migrate your codebase.
1. Create a text file(users.txt) that list all of the users that would appear in your SVN repository and then we need to map them in the following format ‘svn-username = Real Name ‘ for Git.
For Example:
abc-xyz = abc xyz <abc@example.com>
dfg-yui = dfg yui <dfg@example.com>
asd-lkj = asd lkj <asd@example.com>
We can get the list of all the svn-username by running the following command svn log --xml | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = /'

Now, after we get the list of all the users, we just need to map them in the above prescribed format.
2. Clone the svn repository using the following command (git svn clone) git svn clone --authors-file=users.txt --no-metadata -s my_project

By running the above command it will create a new Git repository of our project and we also need to provide our users.txt file in there to remap our users. This conversion can take some time. In my case, it has taken 5 hours to clone it.
Note: The –no-metadata flag tells git to ignore all the SVN junk except the actual commit log.
3. Cleaning up the repository. If you had tags in the SVN repository, these are now remote branches for each tag. To display these tags you need to execute the following command $ cd /path/to/repo git branch -r

For each tag, you need to execute the following command git tag tagname tags/tagname git branch -r -d tags/tagname

4. After that, we just need to add our git origin using the following command git remote add origin git@my-git-server:myrepository.git

5. Then we just need to push our all branches using the following command git push origin --all

So, by using a git-svn tool we can easily migrate our codebase from SVN to Git.



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.