• SVN and GIT
Skip to end of metadata
Go to start of metadata

Basic comparison

bind10 dev guidelines show some good examples: http://bind10.isc.org/wiki/GitGuidelines

what

svn

git

update your local copy

svn up

git fetch

view commit history

svn log | less

git log

show working tree status

svn status

git status

print differences

svn diff | less

git diff

add new file

svn add foobar && svn commit

git add foobar

send local changes to remote repository

svn commit

git commit

create branch

svn cp trunk new && cd new

git branch -b new master

list tags

ls tags

git tag -l

list branches (local & remote)

ls branches

git branch -a

svn2git

Sometimes it may become necessary to transform it and keep in sync as well. While github offers a one time import for svn, a steady update cycle is needed as well (cronjob doing svn up and running the git import again, pushing to git repository).

http://help.github.com/import-from-subversion/

Icon

svn2git could complain about no local user.name set. ignore that.

https://github.com/nirvdrum/svn2git

$ sudo apt-get install git-core git-svn ruby rubygems
$ sudo gem install svn2git

Authors

Git requires a fully mapped name with mail authors file, which can be created with the following - placing it into the default read path ~/.svn2git/authors

$ mkdir ~/.svn2git
$ svn co https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore nagioscore
$ cd nagioscore
$ svn log | grep -E "r[0-9]+ \| .+ \|" | awk '{print $3 " = " $3 " <user@nagios.org>"}' | sort | uniq > ~/.svn2git/authors

 
$ cat ~/.svn2git/authors
 
cvs2svn = cvs2svn <user@nagios.org>
duncan_ferguson = duncan_ferguson <user@nagios.org>
egalstad = egalstad <user@nagios.org>
estanley375 = estanley375 <user@nagios.org>
hendrikb = hendrikb <user@nagios.org>
mguthrie88 = mguthrie88 <user@nagios.org>
ageric = ageric <user@nagios.org>
cvs2svn = cvs2svn <user@nagios.org>
dermoth = dermoth <user@nagios.org>
egalstad = egalstad <user@nagios.org>
estanley375 = estanley375 <user@nagios.org>
kdebisschop = kdebisschop <user@nagios.org>
mguthrie88 = mguthrie88 <user@nagios.org>
tonvoon = tonvoon <user@nagios.org>
uid21444 = uid21444 <user@nagios.org>
zarzax = zarzax <user@nagios.org>

Example: ndoutils

This ones pretty interesting, but not that easy because the svn is not only one, but all projects are nested into that. For that reason, svn2git needs a special flag --no-minimize-url in order to grab the correct svn tree.

$ mkdir -p ~/coding/nagios/git/ndoutils
$ cd ~/coding/nagios/git/ndoutils
$ svn2git -v https://nagios.svn.sourceforge.net/svnroot/nagios/ndoutils --no-minimize-url

you can do that for all projects listed here just by replacing ndoutils in the above example: http://nagios.svn.sourceforge.net/viewvc/nagios/

Push to git repo

Create an empty repository somewhere, e.g. github. Then add the remote origin and push the newly imported svn2git repo remotely. This example tags the new git repo 'ndoutils-svn.git'

$ git remote add origin git@github.com:dnsmichi/ndoutils-svn.git
$ git push origin master

Keep in sync

As of svn2git 2.0 there is a new feature to pull in the latest changes from SVN into your git repository created with svn2git. This is a one way sync, but allows you to use svn2git as a mirroring tool for your SVN repositories.

The command to call is:

$ cd <EXISTING_REPO> && svn2git --rebase

So let's do this, and also push to remote origin then. This will keep our github repos updated (wink)

$ cd ~/coding/nagios/git/ndoutils
$ svn2git --rebase
$ git push origin master

Path

On Debian, the svn2git binary is not linked into PATH. Setting a symlink might help.

# cd /usr/local/bin
# ln -s /var/lib/gems/1.8/bin/svn2git

Possible Errors

command failed  git config --local --get user.name

This is due to an old git version used in Debian Squeeze - http://packages.debian.org/squeeze/git
Rather install the newer version from the Backports repo - http://packages.debian.org/squeeze-backports/git

http://backports.debian.org/Instructions/

# echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> /etc/apt/sources.list.d/squeeze-backports.list
# apt-get update
# apt-get -t squeeze-backports install git git-svn

 

Git Config

If porting the git repo, keep in mind that .git/config needs to contain the svn origin as well.

nagios-svn.git

[core] 
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:dnsmichi/nagios-svn.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[svn-remote "svn"]
        noMetadata = 1
        url = https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore
        fetch = trunk:refs/remotes/svn/trunk
        branches = branches/*:refs/remotes/svn/*
        tags = tags/*:refs/remotes/svn/tags/*
[user]
        name = Michael Friedrich
[branch "nagios-1-x-bugfixes"]
        remote = .
        merge = refs/remotes/svn/nagios-1-x-bugfixes
[branch "nagios-2-x-bugfixes"]
        remote = .
        merge = refs/remotes/svn/nagios-2-x-bugfixes
[branch "nagios-3-0-x-branch"]
        remote = .
        merge = refs/remotes/svn/nagios-3-0-x-branch
[branch "nagios-3-2"]
        remote = .
        merge = refs/remotes/svn/nagios-3-2
[branch "nagios-3-3-branch"]
        remote = .
        merge = refs/remotes/svn/nagios-3-3-branch
[branch "nagios-3-3-test-branch"]
        remote = .
        merge = refs/remotes/svn/nagios-3-3-test-branch
[branch "nagios-3-4"]
        remote = .
        merge = refs/remotes/svn/nagios-3-4
[branch "nagios-3-4@1842"]
        remote = .
        merge = refs/remotes/svn/nagios-3-4@1842
[branch "nagios-3-x-bugfixes"]
        remote = .
        merge = refs/remotes/svn/nagios-3-x-bugfixes

 

ndoutils-svn.git

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[svn-remote "svn"]
        noMetadata = 1
        url = https://nagios.svn.sourceforge.net/svnroot/nagios/ndoutils
        fetch = trunk:refs/remotes/svn/trunk
        branches = branches/*:refs/remotes/svn/*
        tags = tags/*:refs/remotes/svn/tags/*
[svn]
        authorsfile = /home/michi/.svn2git/authors
[user]
[remote "origin"]
        url = git@github.com:dnsmichi/ndoutils-svn.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

 

 

  • No labels