tags:

views:

60

answers:

2

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%Creset - %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative

So, when I run git lg, I see the following:

* 41a49ad - zain - commit 1 message here (3 hours ago)
* 6087812 - zain - commit 2 message here (5 hours ago)
* 74842dd - zain - commit 3 message here (6 hours ago)

However, I want to add the SVN revision number in there too, so it looks something like:

* 41a49ad - r1593 - zain - commit 1 message here (3 hours ago)

The normal git log shows you the SVN revision number, so I'm sure this must be possible. How do I do this?

A: 

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.

VonC
+1  A: 

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/'
UncleZeiv