用于检出不使用 Git 镜像中的 'rNNNNN' 格式的特定 Subversion 修订版的内置命令?

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

我正在从 Subversion 存储库的本地 Git 镜像进行编译,我需要从镜像的 Subversion 修订号中检出特定的提交。

git log 显示如下:通过定位 git-svn-id: xxxx xxxx@revision-number 行,应该可以找到正确的参考并检查它。但是有很多修改,如果我想回到过去,肯定会很尴尬。是否有内置功能来完成此操作?

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

更新:与可能的重复有关。 Checkout the git commit corresponding to a certain revision from the old SVN repository? 中引用的 git svn find-rev 适用于使用 rN 版本号样式的存储库,并非所有 SVN 存储库都是如此,这个也是如此。使用它会导致类似于下面的错误消息。

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

如果您的本地存储库正在使用 git svn 进行管理,那么您可以使用 git svn find-rev:

   find-rev
       When given an SVN revision number of the form rN, returns the
       corresponding Git commit hash (this can optionally be followed by a
       tree-ish to specify which branch should be searched). When given a
       tree-ish, returns the corresponding SVN revision number.

例如:

git svn find-rev r48152

根据 How do I show the SVN revision number in git log? 的回答,我的解决方案是 grep 的修订 ID cut 出 Git 提交哈希。

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

如果 NNNNN 字符串出现在另一个不是提交 ID 的提交消息中,trunk 将匹配 NNNNN 字符串的可能性降至最低。可以通过另一个 cut -b 1-8

管道输出来缩短散列

我希望你的本地 Git 镜像上还有一个 svn-remote 分支。 有了这个它应该很简单。试试这个。

git svn fetch <svn-remote>
git checkout remotes/<Remote Name>
git svn log --show-commit --oneline

参考我在的回答。