When converting from SVN to Git, how do I put the

2019-04-10 17:46发布

问题:

We will be converting our repository from Subversion to Git, but would like to be able to retain the SVN revision number as comments in the bug tracker regularly reference it.

We will be using git svn clone and the process described in John Albin's blog.

Is there a way to include the revision number in the commit message? I'd prefer to do it during the clone, but a post-processing step would be acceptable.

Yes, I know about git svn find-rev, but that requires the SVN repository stick around and the user has network access to it.

回答1:

git svn does this by default: it normally includes a line in every commit message that has the SVN revision number (and some other data) for that commit.

However, the link you posted has you cloning with --no-metadata, which tells git svn not to append the git-svn-id line.



回答2:

It's not clear why you would want the svn revision number in the commit message. As @John Flatness indicates, the git-svn includes the svn revision number in the commit messages.

We found it more useful to create tags for each revision. This seems to better parallel the usefulness of the svn revision numbers. A script that uses git svn find-rev quickly added 10000 tags. Now we can access any historical svn revision number.


Per request here is the script (added here because comments don't seem to handle code well)

#!/bin/bash

declare -i rev

for ((rev = 1; rev < 100; ++rev))
do
    hash=$(git svn find-rev "r$rev")
    if [ -z $hash ]; then
        break
    fi
    # TODO Pad with 0's for small values of rev
    tag="svn_r$rev"
    git tag -a -m "$tag" $tag $hash
done

This just does the first 100 revisions. We stepped by by a 1000 for the first 5000 revs then by a 100. The last 2000 or so commits have individual tags.



回答3:

This script works better for people taking partial branches of svn. Because the break drops out when no revision returned. Try this one. Just need to make the 50000 what every your max revision number is.

declare -i rev

for rev in {1..50000}
do
    echo $rev
    hash=$(git svn find-rev "r$rev")
    tag="svn_r$rev"
    if [ -z $hash ] 
    then
        echo no tag
    else
        echo $hash
        echo $tag
        git tag -a -m "$tag" $tag $hash
    fi
done

echo Thats it !