Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find SVN revision in subgit repo?

Tags:

git

subgit

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?

like image 553
Magnus Avatar asked Jan 19 '15 09:01

Magnus


1 Answers

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.

like image 108
Dmitry Pavlenko Avatar answered Sep 27 '22 23:09

Dmitry Pavlenko