How to find SVN revision in subgit repo?

前端 未结 1 806
谎友^
谎友^ 2021-02-09 05:31

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

1条回答
  •  不思量自难忘°
    2021-02-09 05:46

    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.

    0 讨论(0)
提交回复
热议问题