Search code examples
gitsvnmigrationgit-svnsvn2git

SVN to Git Migration. How to migrate a non standard SVN layout to Git


I am currently working on migrating an svn source controlled project into Git (BitBucket). I have followed the guide by Atlassian and nearly got to the end but encountered the following error when running the command git push -u origin --all:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date.

I believe this is because the SVN layout is not the standard layout. I have had to specify the trunk, branches and tags like so:

git svn clone --trunk=/main --branches=/branches/Sprints/Iteration_1 --branches=/branches/Sprints/Iteration_2 --tags=/tags --authors-file=authors.txt svn://svn-project/projExample projExample

But I cannot figure out how to proceed and push the repo to BitBucket. Any help would be greatly appreciated!

It is also worth noting that I have tried the command git push origin master and received the below error:

error: src refspec master does not match any.
error: failed to push refs to '[my bitbucket origin]'.

An example of a previous question I have found is here. But this didn't seem to help. Perhaps I am doing something wrong?

Below are the commands in order run to get to the initial error described above:

  1. java -jar /svn-migration-scripts.jar verify
  2. java -jar /svn-migration-scripts.jar authors svn://svn-project/projExample > authors.txt
  3. Edit the authors.txt file to match all the current users names & emails.
  4. git svn clone --trunk=/main --branches=/branches/Sprints/Iteration_1 --branches=/branches/Sprints/Iteration_2 --tags=/tags --authors-file=authors.txt svn://svn-project/projExample projExample
  5. java -DFile.encoding=utf-8 -jar /svn-migration-scripts.jar clean-git --force
  6. git svn fetch
  7. java -Dfile.encoding=utf-8 -jar /svn-migration-scripts.jar sync-rebase
  8. java -Dfile.encoding=utf-8 -jar /svn-migration-scripts.jar clean-git --force
  9. git remote add origin https://[email protected]/projExample.git
  10. git push -u origin --all
  11. Nothing happens.

Solution

  • After a lot of trial and error I have come to the conclusion that the SVN structure used here was just far too complicated. I updated the command to

    git svn clone --trunk=main --branches=branches/*/* --tags=tags/* --authors-file=authors.txt svn://svn-project/projExample projExample
    

    Which solved the issue but resulted in the command taking 7 days to run! This shows that the structure was far too complicated!

    As a result of this I decided to use the svn branch containing the latest code as the trunk which successfully added the history but did not create the required branches. I decided that this was good enough as the command would run within 2 hours. The command I went for was more like this:

    git svn clone --trunk=branches/Sprints/Iteration_2 --authors-file=authors.txt svn://svn-project/projExample projExample.
    

    If I was advising someone else on this I would say to go straight for the command above as it is quick and does the job!

    As an extra below are the commands needed to sync SVN to the Git repo. basically you need to merge origin/trunk and master and then push

    git svn fetch
    git merge origin/trunk
    git push origin master