vfclists vfclists - 2 months ago 18
Git Question

Built-in command to checkout a specific Subversion revision which doesn't use the 'rNNNNN' format from a Git mirror?

I am compiling from a local Git mirror of a Subversion repository and I need to checkout out particular commits from the Subversion revision number from the mirror.

The

git log
displays something like this: and by locating the
git-svn-id: xxxx xxxx@revision-number
line it should be possible to locate the right reference and check it out. But there are lots of revisions and it is bound to get awkward if I want to go way back in time. Is there a built-in to accomplish this?

commit xxxx-yyyy-fb12992fabd6a1165697ded73851d26993
Author: mattias <mattias@4005530d-fff6-0310-9dd1-cebe43e6787f>
Date: Fri Mar 6 16:25:06 2015 +0000

fpcunit: guitestrunner: scroll to first error after run, patch from Graeme, issue 27613

git-svn-id: http://svn.freepascal.org/svn/lazarus/trunk@48152 4005530d-fff6-0310-9dd1-cebe43e6787f


UPDATE: relating to possible duplicate.
git svn find-rev
referenced in Checkout the git commit corresponding to a certain revision from the old SVN repository? applies to repositories that use the
rN
style of revision number, and that is not the case for all SVN repositories, and this one as well. Using it results in the error messages similar to the one below.

fatal: Not a valid object name 95059
cat-file commit 95059: command returned error: 128

Answer

Following the answer from How do I show the SVN revision number in git log?, my solution is to grep for the revision id an cut out the Git commit hash.

git log -z | tr '\n\0' ' \n' | sed 's/\(commit \S*\) .*git-svn-id: \  
svn:[^@]*@\([0-9]*\) .*/\1 r\2/' | grep trunk@NNNNN | cut -d " " -f 2

The trunk minimizes the chance of matching the NNNNN string if it appears in another commit message in which is not the commit id. The hash can be shortened by piping the output through another cut -b 1-8