To make a start I can say that I personally prefer using Git as Version Control System. I use Subversion and Mercurial for some reasons too, but I do not really like to work with them.
Because of this I wanted to convert some Subversion repositories to Git. If you also have planned to do this, the following may help you.
Three different ways for the conversion:
- Copying the source code:
- Using git-svn:
- Using svn2git:
The easiest and fastest way is simply copying the source code into an empty Git repository. For me this solution was impracticable, because you will loose the history.
# Create and switch to new folder
mkdir $GIT_REPO
cd $GIT_REPO
# Copy all files from the Subversion directory
# Use -C option to ignore .svn directories
rsync -C $PATH_TO_SVN_REPO/* $PATH_TO_GIT_REPO/
# Do the Git steps
git init
git add *
git commit -asm "Initial commit"
The next way to convert the repository is using git-svn. With git-svn you are able to adopt all branches and the whole history. The only unsuitable thing is converting tags, because they are created as branches by default and you need to switch them manually afterwards.
# Install the software
(sudo) apt-get install git-svn
# Make and switch to new folder
mkdir $GIT_FOLDER
cd $GIT_FOLDER
# Convert the repository
git svn clone $SVN_URL --no-metadata --stdlayout .
# Update the repository
git svn fetch
Svn2git is a utility which uses git-svn internally to do the real conversion, but in addition it does some more jobs around this to perfect the system. With this you will have a accurate converted repository. It uses Ruby, so you need to install some additional packages.
You can use svn2git for some special actions and custom purposes. If you need some more information you can take a look at the README.
# Install the software
(sudo) apt-get install git-svn ruby rubygems
(sudo) gem install svn2git
# Make and switch to new folder
mkdir $GIT_FOLDER
cd $GIT_FOLDER
# Convert the repository
svn2git $SVN_URL
# Update the repository
svn2git --rebase
I hope this tutorial helps you to save some time and troubles. If you have feedback, regards, corrections or questions please let me know and do not hesitate to comment!
I will probably write something about Version Control Systems, like a comparison or Cheat-Sheets, in other blog posts.
Thanks for this nice tutorial, I’m sure I will use it some day ^^ Keep these posts coming, they’re very helpful =)
Thank you for your comment kel I try to post at least once a month, but I am short in time^^