Lately I’ve been converting a Subversion repository to Git using git-svn. The conversion is a breeze, you just need time.
$ mkdir killerapp
$ cd killerapp
$ git svn init -t tags -b branches -T trunk https://mysvn.com/killerapp
Initialized empty Git repository in .git/
$ git svn fetch
So now you have a working Git repo, fine. The only concern is how git-svn handles tags. Each SVN tag is converted into a branch, not a tag. For instance, tag 1.2 becomes git branch tag/1.2. git-svn might have a good reason for doing it but this is a bit disturbing to me, especially when you have dozens of tags polluting your ‘git branch’ output.
So I intended to convert all these branches into real tags, and delete them. Here is the command I came up with:
$ git-for-each-ref refs/remotes/origin/tags | cut -d / -f 5- |
while read ref
do
git tag -a "$ref" -m"say farewell to SVN" "refs/remotes/origin/tags/$ref"
git push origin ":refs/heads/tags/$ref"
git push origin tag "$ref"
done