Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-svn

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?

like image 762
Zain Avatar asked May 20 '10 01:05

Zain


People also ask

How do I find my SVN revision number?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

What is SVN revision number?

As you saw in the section called “Revisions”, revision numbers in Subversion are pretty straightforward—integers that keep getting larger as you commit more changes to your versioned data. Still, it doesn't take long before you can no longer remember exactly what happened in each and every revision.


2 Answers

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.

like image 68
VonC Avatar answered Sep 21 '22 05:09

VonC


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.

like image 38
kakyo Avatar answered Sep 18 '22 05:09

kakyo