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

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 -->   ...

President - Association of Computer Engineering Students

I was selected to be the president of ACES, Association of Computer Engineering Students, the official student body of the Department of Computer Engineering Students. ACES Site :  aces.ce.pdn.ac.lk  It was a great opportunity to work with fellow undergraduates, lecturers, senior graduates, and industry. Until now We were able to organize few events in University of Peradeniya and Colombo. This event was organized by ACES Council, a group of 14 undergraduates. The events are, ACES Hackathon - This is an inner hackathon for undergraduates in the University of Peradeniya. ACES Hackathon, held annually for the last 5 years was held from the 29th of April to the 1st of May 2016 at the Faculty of Engineering, University of Peradeniya. The Hackathon brings together undergraduates from the Faculty of Engineering and Science for 3 days to develop their creative skills to provide innovative IT solutions. This year there were 150+ participants.   www.readme.lk/saw-ac...