When I want to get a local hash of a commit based on SVN revision id, I usually run git svn find-rev
. However, the one big inconvenience is that this command will only look for the commit in the current branch, or in the branch explicitly specified in the command after the revision.
Sometimes, I only know the revision id, and I want to find a local hash without knowing the branch name. Is there a way to do it with git svn find-rev
? It would make sense, knowing that SVN revisions are unique.
EDIT:
Turns out, there is no good way to do it.
I accepted the answer, which provides a solution, but it takes too long to search a repository with huge number of branches, like mine. I ended up writing my own shell function and using a regular svn
in combination with git svn
, which works much faster:
gitrev()
{
if [ -z "$1" ]; then
echo "${FUNCNAME[0]} <revision> [git_args]"
return 1
fi
local rev b
rev="$1"
shift
b="$(svn log -v -c "$rev" "$SVN_BRANCHES_URL" | grep -m1 -Po '/branches/\K[^/]+')" &&
git svn find-rev "r${rev#r}" "origin/$b" "$@"
}
If you use it, you may need to replace grep -P
part if you're not on GNU/Linux. Revision can be specified with or without "r" prefix.
To search in all local branches you can e. g. do
git for-each-ref --format='%(refname)' refs/heads/ | xargs -l git svn find-rev r123456
To have it more reliable but still fast, you can do it with a little bit more complex line that looks through all refs until a match is found and then aborts, e. g. like
while read ref; do result="$(git svn find-rev r123456 "$ref")"; [ -n "$result" ] && echo $result && break; done < <(git for-each-ref --format='%(refname)')