How to find SVN revision in subgit repo?
Asked Answered
G

1

7

I'm using Subgit to access a Subversion repo. It works great, but at times, especially when communicating with users who access the repo using an ordinary Subversion client, I'd really like to find to which SVN revision a particular changeset corresponds.

Can I, using git find the SVN revision number somewhere in my local repo?

Gelatinous answered 19/1, 2015 at 9:35 Comment(0)
R
9

Yes, you can do that easily. You should just modify your .git/config file in the cloned Git repository to add

[remote "origin"]
...
fetch = +refs/svn/map:refs/notes/commits

option and then run git fetch, as it is described in "Recommended client-side Git configuration" section of SubGit book. After that git log command on the cloned repository will display revision numbers.

If you want to do that on the server side (and if you don't use Git notes for other purposes in your project), you can run on the server machine

$ git update-ref refs/notes/commits refs/svn/map

for one-time Git notes creation or you can run in that repository

$ cd refs
$ mkdir notes
$ echo "refs: refs/svn/map" > notes/commits

to make refs/notes/commits follow refs/svn/map that is updated by SubGit and stores the latest revision <-> SHA-1 mapping. After that git log on the server will also display revision numbers.

If you want to convert revisions to SHA-1 hashes in scripts (after setting up Git notes in any way mentioned above), you can use this command

$ git log --format="%H %N" --all

in combination with line-parsing functions. E.g. if you don't care much about corner cases (e.g. branch name of name "r$REV branch"), to get SHA-1 and changed branch(es) name by revision REV you can run

$ git log --format="%H %N" --all | grep "r$REV "

Similarly you can grep SHA-1 or branch names here.

Recency answered 19/1, 2015 at 11:20 Comment(3)
Excellent, that solved it. I'm guessing I didn't find that using my favourite search engine because those instructions don't actually mention the word "revision" anywhere; I didn't think of searching for "mapping information" ;)Gelatinous
A followup question, say that I would like to push the SVN mapping fetched from subgit to another pure-git repo, how would I accomplish that?Gelatinous
How do you achieve the same for submodules? It works fine for the superproject, but no clue on how to get the svn revisions for its submodules. Replying to myself: edit the config file in .git/modules/submodule_name/configBaier

© 2022 - 2024 — McMap. All rights reserved.