Splitting an SVN repository? How to move from a single SVN repository to multiple repositories without loosing project history
This idea will enable you to 'split' your single repository into multiple smaller repositories without loosing history. As you can see, the word split here is in quotes because it is not a real split, but rather a walk-around the fact that dumping a repository and importing sub-sets/directories that may have interlinked merges and branches is a risky venture that is rarely worth the sweat and toil.
I have found myself in the following situation: When I created my project repository three years ago, it was a good idea - or it looked like to keep all the projects in one repository. After all, I was the sole developer for all the development that I did, and I did not really share anything outside my office. Over the last one year, I have come to realize that my decision from three years ago was short-sighted and unwise. I am now collaborating more and more with others and the need has arisen (a few times already) to allow other developers a glimpse into my work, or even to get help in developing a specific part of a project. Without SVN, collaboration is a nightmare. Without any further stories, here is my approach to creating smaller repositories, and still allowing access to the complete 3+ year history.
- Create a new repository for each project, using best practices to get the size right this timesvnadmin create mynewrepository1
- Go to your local drive and checkout the repository that you just createdsvn co svn+ssh://pathtorepo .
- Create/edit an SVN externals recordsvn propedit svn:externals .
* if you get the error message "svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set, and no 'editor-cmd' run-time configuration option was found" do not panic, you just need to set a default editor for SVN to useexport SVN_EDITOR=vimwill allow you to use vim for this session ... you can permanently set this in your bash profile file ~/.bash_profile - When done with the editor setup, run the externals command again and you should get a new editor window. In there, add value pairs to relate a virtual name to an external repository branch e.g:archives_myproject svn+ssh://username@domainofsvnserver/pathtooldrepository/archives/branch/to/...
- Save the text file and exit, you should see something to the effect that the changes were saved
- Now, you need to commit your changes. Assuming that your local copy was current, you can just commit, otherwise update it before committing to avoid an error message
svn update
svn commit -m "adding svn externals definition"
* you can just commit without a message, but I have a good practice of always adding useful notes - Voila! , now you can checkout your new repository and it will always have a directory/branch called archives_myproject that contains the entire history of your project. Obviously, going forward, you can checkin new changes in the new repository
- DO NOT do any more checkins to the old repository, you can, but it is not good practice. You should keep it for archival purposes/reference
Advantages
- Since the externals definition is pointing to the specific branch where you used to store your smaller project changes, you are not being forced to share access to all the projects in the bigger repository. So new collaborators cannot snoop into projects they should not be looking at
- You can maintain the good practice of keeping separate project repositories without loosing history. You can go forward in the right direction while maintaining the ability to refer to and even compare a file to the 3 year history (in my case)


