Friday, February 11, 2011

Converting SVN tags to git tags.

I recently moved a subversion repository to git. I used git-svn for the initial conversion, but it doesn't actually create real git tags. It merely creates specially named branches. I found this script that did almost what I wanted. Aside from the path to the tags changing, it didn't preserve the date or the message of the original tags. Below you'll find my quick hack that did it for me.

#!/bin/bash

TAGS=($(git for-each-ref refs/remotes/tags | cut -d / -f 4-))

for tag in "${TAGS[@]}"; do
MSG=$(git log -1 --pretty=%B "refs/remotes/tags/$tag")
export GIT_COMMITTER_DATE=$(git log -1 --pretty=%ci "refs/remotes/tags/$tag")
GIT_COMMITTER_DATE="$GIT_COMMITTER_DATE" git tag -s -m "$MSG" "$tag" "refs/remotes/tags/$tag"
done

No comments: