How to find SVN revision in subgit repo?

拈花ヽ惹草 提交于 2019-12-03 07:28:29

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!