4

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.

John Franklin
  • 4,962
  • 1
  • 23
  • 27
  • Is this what you are looking for? http://stackoverflow.com/questions/1127177/to-put-the-prefix-revision-number-to-codes-by-git-svn – Ali Aug 18 '11 at 15:23
  • No, thats for creating URLs mapping to a web front-end like GitWeb. We're looking for the Git commit message itself to read: "SVN r123: Frobbed the baz." – John Franklin Aug 18 '11 at 15:27

3 Answers3

5

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.

John Flatness
  • 32,469
  • 5
  • 79
  • 81
  • It's the "and some other metadata" that we didn't need or want. The full git-svn-id line is too much noise for the one piece of data we needed. – John Franklin Aug 17 '18 at 14:39
3

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.

Bill Door
  • 18,272
  • 3
  • 32
  • 37
  • Would you mind sharing that script please? I think this solution is pretty neat. – Tomas Andrle Oct 20 '12 at 18:46
  • 1
    @BillDoor "It's not clear why you would want the svn revision number in the commit message." - an example is signed and dated documentation which refers to the svn version, which needs to legally be kept available for many years even as the underlying repository is changed from svn to git for business reasons – simpleuser Sep 27 '17 at 20:36
0

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 !
John Franklin
  • 4,962
  • 1
  • 23
  • 27
Philip
  • 1