How to import svn branches and tags into git-svn?
You'll need several steps.
-
supply proper trunk, branches and tags folder names and fetch svn repo:
git svn init -t tags -b branches -T trunk https://mysvn.com/svnrepo git svn fetch
-
Since tags in svn are real branches, create git tags from tag branches:
git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags | cut -d / -f 3- | while read ref do echo git tag -a $ref -m 'import tag from svn' done
-
Delete tag branches
git for-each-ref --format="%(refname:short)" refs/remotes/tags | cut -d / -f 2- | while read ref do echo git branch -rd $ref done
-
Since tags marked in the previous step point to a commit "create tag", we need to derive "real" tags, i.e. parents of "create tag" commits.
git for-each-ref --format="%(refname:short)" refs/tags | while read ref do tag=`echo $ref | sed 's/_/./g'` # give tags a new name echo $ref -\> $tag git tag -a $tag `git rev-list -2 $ref | tail -1` -m "proper svn tag" done
All we have to do now is to remove old tags.
This draws on Vanuan's answer above, but it preserves the message of the original svn
tag in the new git
tag.
$ git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags \
| while read BRANCH REF
do
TAG_NAME=${BRANCH#*/}
BODY="$(git log -1 --format=format:%B $REF)"
echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2
git tag -a -m "$BODY" $TAG_NAME $REF^ &&\
git branch -r -d $BRANCH
done
This is the same as nicolai.rostov's answer above, but i just change the refs path
I replaced refs/remotes/tags
by refs/remotes/origin/tags
I'm using git version 2.1.1
into cygwin
terminal.
$ git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/origin/tags \
| while read BRANCH REF
do
TAG_NAME=${BRANCH#*/}
BODY="$(git log -1 --format=format:%B $REF)"
echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2
git tag -a -m "$BODY" $TAG_NAME $REF^ &&\
git branch -r -d $BRANCH
done