如何在 git log 中显示 SVN 修订号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2870506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I show the SVN revision number in git log?
提问by Zain
I'm customizing my git log to be all in 1 line. Specifically, I added the following alias:
我正在将我的 git 日志自定义为 1 行。具体来说,我添加了以下别名:
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:
所以,当我运行时git lg
,我看到以下内容:
* 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:
但是,我也想在那里添加 SVN 修订号,所以它看起来像:
* 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?
正常git log
显示 SVN 修订号,所以我确定这一定是可能的。我该怎么做呢?
采纳答案by UncleZeiv
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 log
向您显示 SVN 修订号”时,我猜您的意思是您正在处理由 处理的存储库git svn
,默认情况下,它会在同步提交的末尾添加如下一行:
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.
现在,就 git 而言,这只是随机文本,所以我怀疑您是否可以找到从那里%
读取######
修订号的访问器。
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:
在这一点上,您最好的选择是自己解析 plain 的输出git log
。这是一个粗略的起点:
git log -z | tr '\ngit svn find-rev $(git log --max-count 1 --pretty=format:%H)
' ' \n' | sed 's/\(commit \S*\) .*git-svn-id: svn:[^@]*@\([0-9]*\) .*/ r/'
回答by VonC
Consider the command git svn
考虑命令 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)
- 它具有与以下类似的日志功能
git log
:git svn log
- 它具有
find-rev
选项(从 SHA1 密钥检索 SVN 修订版)(在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 onewhich is not exactly what you want but still can give some idea) might be in order.
不过,我不确定您是否可以在一个命令行中组合这两个选项。
一个脚本(有点像这个,它不是你想要的,但仍然可以提供一些想法)可能是有序的。
sdaauadds in the comments:
An example of this:
这方面的一个例子:
git rev-parse HEAD
Adversusadds in the comments:
Note that
find-rev
searches in the current branch, so if you're inmaster
andrxyz
happened in a branch,find-rev
will not find it.
You can give-B
(before) or-A
(after) options for a wider search, seegit svn find-rev
man page section.
请注意,
find-rev
在当前分支中搜索,因此如果您在某个分支中master
并rxyz
发生了这种情况,find-rev
将找不到它。
您可以为更广泛的搜索提供-B
(before) 或-A
(after) 选项,请参阅git svn find-rev
手册页部分。
回答by kakyo
Run:
跑:
git svn find-rev <commit_hash>
which gives you git commit hash.
这给你 git commit hash。
Then use that commit hash to run:
然后使用该提交哈希运行:
git svn log --oneline -1 | cut -d '|' -f1
Which gives you svn revision.
这给了你 svn 修订版。
回答by user1264366
Ended up with something like this:
结束了这样的事情:
##代码##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.
这给出了该 repo 的最后一个修订版(您可以调整git svn log
参数以显示另一个修订版,但保留--oneline
和-1
),但带有尾随空格(类似于"r9441 "
),我认为应该很容易去除。
Hope it helps...
希望能帮助到你...