Skip to main content

SVN to GIT Migration with revision history


This blog explains the process I have followed while moving one of code branch of one of the projects to Gitlab.

SVN to Git migration can be done using the git-svn command in Git.  Documentation about this command can be found from here.



My Company svn repository can be accessed using two ways


  • svn+ssh://192.168.x.x/usr/local/svnroot/branches/PROJECT/PROJECT_BRANCH
  • http://svn.companyName.net/repos/svnroot/branches/PROJECT/PROJECT_BRANCH


SVN to GIT migration can be done using one of the above-mentioned URLs.  Git can be installed and configured to use its inbuilt SSH client or third party ssh client (https://6xgate.github.io/TortoisePlink/ )


First of all, this process should be run in a server where the system does not go idle. I have tried this on my PC. But when I have locked the PC, it crashes. Therefore I have tried this in one of our internal server.


I have tried to get SVN revision history when the Project main branch was created. (at 2015).


I have first tried to clone the git repository using the 1st URL. When cloning the svn repository, it is trying to access a deeper level to get svn changes history. I have access to those deeper level, git-svn requiring ssh password for each new connection created to access svn history. This needs to enter the password more than 100 times. (As per my investigation, this can be avoided by configuring private-public ssh key. : But I did not try that.)


Due to an authentication error, I have tried to use the second URL. This worked well and It required a password only once.


Although in both processes, it requires a lot of time to clone SVN repository to Git with history.


Reference url :


Part 1: Move code  to empty Git repository



Method 1
git svn clone --no-minimize-url http://svn.companyName.net/repos/svnroot/branches/PROJECT/PROJECT_BRANCH -r541750:HEAD  


Note: I have added two parameters with this command.
  • --no-minimize-url   - Passing --no-minimize-url will allow git-svn to accept URLs as-is without attempting to connect to a higher level directory. This option is off by default when only one URL/branch is tracked (it would do little good).


  • -r541750: HEAD   - Using this command, we can get revision history starting from 541750 to HEAD. This will reduce the time to load all the file history.


git svn fetch


If the first command is failed, using fetch, the user can resume the process using “git svn fetch”.  (git svn clone runs init and fetch)


git svn rebase


This fetches revisions from the SVN parent of the current HEAD and rebases the current (uncommitted to SVN) work against it. This works similarly to svn update or git pull except that it preserves linear history with git rebase instead of git merge for ease of dcommitting with git-svn.

git remote add master http://gitlab.companyName.net/project-group/sub-group/project_name.git


git push --set-upstream master master


git commit -m "Initial commit of SVN to GIT"


//Update master & after clone all svn changes merge
git svn rebase
 
// git master update

git push --all



Part 2: Sync between GitLab and SVN repository

If you already have moved code to GitLab and but still using SVN repository, then you can update
the GitLab repository using the following commands.

git svn rebase

This fetches revisions from the SVN parent of the current HEAD and rebases the current (uncommitted to SVN)
work against it.
This works similarly to svn update or git pull except that it preserves linear history with git rebase
instead of git merge for ease of dcommitting with git-svn.

git svn dcommit

Commit each diff from the current branch directly to the SVN repository, and then rebase or
reset (depending on whether or not there is a diff between SVN and head).
This will create a revision in SVN for each commit in Git.
When an optional Git branch name (or a Git commit object name) is specified as an argument,
the subcommand works on the specified branch, not on the current branch.

Reference: https://git-scm.com/docs/git-svn#git-svn-emdcommitem

Comments

Popular posts from this blog

REST VS SOAP

SOAP and REST both allow you to create your own API. API stands for Application Programming Interface. It makes it possible to transfer data from an application to other applications. An API receives requests and sends back responses through internet protocols such as HTTP, SMTP, and others.  Many popular websites provide public APIs for their users, for example, Google Maps has a  public REST API  that lets you customize Google Maps with your own content. There are also many APIs that have been created by companies for internal use. There are significant differences between SOAP and RESTful web services. The bullets below break down the features of each web service based on personal experience. REST RESTful web services are stateless. You can test this condition by restarting the server and checking if interactions survive. For most servers, RESTful web services provide a good caching infrastructure over an HTTP GET method. This can improve the performance...

Java 11 Modularity and Spring REST

I have recently started working on creating a REST API for a client project.  I was using Java 8 for my past developments. Since Java 11 was introduced in the last September  (https://en.wikipedia.org/wiki/Java_version_history) I thought of developing the REST API in Java 11. Java 11 is having major changes after Java 8. Java 11 is having a concept of modules (This was introduced after Java 9). Several libraries are acting as separate modules. Those are not included in JDK and those have to be imported separately. Ref : http://openjdk.java.net/jeps/261 (I have experienced this in JBoss7 also. They were using the module system and each service can specify which modules which are using. Those modules can be manually configured by the user.) One example is that you have to import the Java fx library separately (For GUI). Java-Fx is decoupled from JDK. <!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->   ...