Svn to Git migration an easy guide
Subversion (SVN) is a central version control system (VCS) while Git is a distributed version control system.
SVN has been a great source control system but the Git brings some advanced features like — distribution, performance, easy branches, easy merges, stash — are hard to pass up. All these makes the Git more advantageous than the Svn.
There are many way to migrate from Svn to Git. In this article, we will use the basic Git commands for migration in a simple and easy way.
Objective: Main objective was to maintain all commit history with author wise from Svn to Git.
Steps:
Step 1: Check your set up for Git & Svn. You have to download migration Script to check your system is OK for migration. You can download JAR “svn-migration-scripts.jar” from Url https://bitbucket.org/atlassian/svn-migration-scripts/downloads/ . Now run the commnad:
java -jar svn-migration-scripts.jar verify
It will display below sample result.
Version can be differ: svn-migration-scripts: using version 0.1.56bbc7fGit: using version 2.13.0.windows.1Subversion: using version 1.9.7git-svn: using version 2.13.0.windows.1
Step 2: Generate authors for Svn. We need to create a authors text file that maps Svn usernames to their Git counterparts. Run the below command to generate authors
java -jar svn-migration-scripts.jar authors <SVN_REPO_URL> > authors.txt
Step 3: Clone the SVN Repository. The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Run the below command.
git svn clone --authors-file=authors.txt <SVN_REPO_URL> project_git
This command will start the migration of SVN repo to git inside the project_git directory. Sample OutPut:r33396 = 6a33cc5976a49620a42ffe0e0e209a3e18a376c5 (refs/remotes/git-svn) M XXXXXXXXr33397 = 68c724956066cdc7b22f019f30649cb63a30b741 (refs/remotes/git-svn)
Step 4: Once command completed. Go inside project_git directory to check your project up to date.
Step 5: Synchronization. Synchronize your Git repository with new commits in the original SVN repository. Run command to fetch new Svn commit:
git svn fetch
Now run the command to apply changes:
git svn rebase
Note: We are skipping author synchronization here.
Step 6: Move your migrated SVN repo on GIT. Please follow below steps:
- Create a repo on bitbucket.
- Get Repo Url.
- Go inside your project_git directory.
- Run the command git remote add origin <GIT_REPO_URL>
- Run the command . It will push the code on your git repo.
git push origin master
Step 7: Follow step 5 to synchronize your svn repo to new git repo. After synchronization run the command to push changes on git.
git push origin master
That’s done !!