How do I show the SVN revision number in git log?

前端 未结 4 357
抹茶落季
抹茶落季 2020-12-24 11:56

I\'m customizing my git log to be all in 1 line. Specifically, I added the following alias:

lg = log --graph --pretty=format:\'%Cred%h%Creset - %C(yellow)%an         


        
相关标签:
4条回答
  • 2020-12-24 12:27

    Run:

    git rev-parse HEAD
    

    which gives you git commit hash.

    Then use that commit hash to run:

    git svn find-rev <commit_hash>
    

    Which gives you svn revision.

    0 讨论(0)
  • 2020-12-24 12:28

    Consider the command git svn

    • it has a similar log function than git log: git svn log
    • it has the find-rev option (to retrieve the SVN revision from a SHA1 key) (introduced in git 1.6.0)

    I am not sure of you can combine those two options in one command line though.
    A script (a bit like this one which is not exactly what you want but still can give some idea) might be in order.


    sdaau adds in the comments:

    An example of this:

    git svn find-rev $(git log --max-count 1 --pretty=format:%H)
    

    Adversus adds in the comments:

    Note that find-rev searches in the current branch, so if you're in master and rxyz happened in a branch, find-rev will not find it.
    You can give -B (before) or -A (after) options for a wider search, see git svn find-rev man page section.

    0 讨论(0)
  • 2020-12-24 12:37

    When you say that "the normal git log shows you the SVN revision number", I guess you mean that you are dealing with a repository handled by git svn, which by default adds a line like this at the end of the synchronized commits:

    git-svn-id: svn://path/to/repository@###### <domain>
    

    Now, as far as git is concerned, this is just random text, so I doubt that you can find a % accessor to read the ###### revision number from there.

    At this point your best option would be to just parse the output of plain git log by yourself. Here's a crude starting point:

    git log -z | tr '\n\0' ' \n' | sed 's/\(commit \S*\) .*git-svn-id: svn:[^@]*@\([0-9]*\) .*/\1 r\2/'
    
    0 讨论(0)
  • 2020-12-24 12:38

    Ended up with something like this:

    git svn log --oneline -1 | cut -d '|' -f1
    

    That gives the last revision from that repo (you can tweak git svn log parameters for showing another revision, but keep --oneline and -1), but with a trailing whitespace (something like "r9441 ") that I think should be easy to strip out.

    Hope it helps...

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