我怎样才能用最近的标签来装饰一个git日志? [英] How can I decorate a git log with its nearest tag?

查看:149
本文介绍了我怎样才能用最近的标签来装饰一个git日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

     code> commit 9e895ace5d82df8929b16f58e9f515f6d54ab82d(tag:v3.10-rc7)
作者:Linus Torvalds< torvalds@linux-foundation.org>
日期:6月22日星期六09:47:31 2013 -1000

Linux 3.10-rc7

这些信息有助于跟踪哪个标签(或分支)包含此提交。在查看一组受限制的文件(比如一个子目录)时,不必为这些提交提供标签。有没有办法在日志输出中加入对标签的引用?



我之前提到 git describe ,但是这会产生 v3.10-rc7-135-g98b6ed0 ,它与提交此更改的分支标记相关。我正在寻找的是提交之间的标签名称。



为了清楚起见,这是目前的情况:

  $ git log --decorate --oneline 
98b6ed0(HEAD,origin / master,master)合并git://git.kernel.org/pub/scm/linux/ kernel / git / davem / net
1a506e4合并分支'drm-fixes'git://people.freedesktop.org/~airlied/linux
578a131 dlci:在dlci_del()中验证网络设备
11eb264 dlci:在调用__dev_get_by_name()之前获取rtnl_lock()
...
9e895ac(标记:v3.10-rc7)Linux 3.10-rc7

我想要的是这样的:

  98b6ed0(v3.10-rc7 +,HEAD,origin / master,master)合并git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 
1a506e4(v3.10- rc7 +)合并分支'drm-fixes'git://people.freedesktop.org/~airlied/linux
578a131(v3.10-rc7 +)dlci:验证dlci_del()中的网络设备
11eb264(v3.10-rc7 +)dlci:在调用_之前获取rtnl_lock _dev_get_by_name()
...
9e895ac(tag:v3.10-rc7)Linux 3.10-rc7

使用 git describe 的输出,而不是提交散列会显示如下内容:

  $ git log --decorate --oneline -n​​4 | awk'{system(git describe$ 1| tr -d'\''\\\
'\''); $ 1 =; print}'
v3.10-rc7-135 -g98b6ed0(HEAD,origin / master,master)合并git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
v3.10-rc7-54-g1a506e4合并分支'drm-fixes'of git://people.freedesktop.org/~airlied/linux
v3.10-rc6-81-g578a131 dlci:在dlci_del()中验证网络设备
v3.10 -rc6-80-g11eb264 dlci:在调用__dev_get_by_name()
...
v3.10-rc7(标记:v3.10-rc7)之前获取rtnl_lock Linux 3.10-rc7

正如您所看到的,较旧的标记名称将用作参考点,而不是提交合并的点。出于说明的目的,我在这里使用 git log --oneline ,但我实际上想要使用更完整的输出,例如 git log -p --stat

解决方案 - git describe 的第一个父元素参数(在git 1.8.4中引入)显示了从。为了在提交后看到第一个标记的关系,请使用 git describe --contains 。当你在历史中深入研究时,这个选项变得非常慢(约6秒)。



命令 git name-rev 可用于注释 git rev-name 并使用 - graph - color $ c>太!从它的手册页:


给定一个提交,找出它相对于本地引用的位置。说有人
写了关于那个梦幻般的提交
33db5f4d9027a10e477ccf054b2c1ab94f74c85a。当然,你可以看看提交,
,但它只会告诉你发生了什么,但不会显示上下文。



输入 git name -rev

 %git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a 
33db5f4d9027a10e477ccf054b2c1ab94f74c85a标签/ v0.99 〜940

现在你明智了,因为你知道它在v0.99之前发生了940次修改。 / p>

您可以做的另一件好事是:

 %git log | git name-rev --stdin 


每个40字符的SHA-1哈希如下所示(突出显示的部分由 git name-rev 添加)。

 
commit 1ee2dcc2245340cf4ac94b99c4d00efbeba61824 (tags / v3.13-rc1〜33)
合并:4457e6f 091e066
作者:Linus Torvalds

合并git://git.kernel.org/pub/scm/linux/kernel/git/davem/net

commit b4089d6d8e71a7293e2192025dfa507a04f661c4 (tags / v3.13-rc1〜7 ^ 2〜6 ^ 2 ^ 2〜8)
作者:Felix Fietkau

rt2x00:修复HT描述符处理修复中的崩溃错误
...
commit dfb6b7c109a7f98d324a759599d1b4616f02c79f (tags / v3.12-rc7〜20 ^ 2〜20 ^ 2 ^ 2〜11)
作者:Stanislaw Gruszka
日期:Mon Sep 23 04:08:13 2013 +0200

恢复rt2x00pci:尽可能使用PCI MSI

这将恢复提交9483f40d8d01918b399b4e24d0c1111db0afffeb (tags / v3.11-rc1 〜16 ^ 2〜103 ^ 2 ^ 2〜 111)






一个用于后期处理的awk脚本 git log 输出可在 https://git.lekensteyn。 nl / scripts / tree / git-log-describe.awk
(在我知道 git rev-name 之前写的)。特性:


  • 考虑来自 commit< hash> 字符哈希(与 - abbrev-commit 一起工作)。

  • 支持 git log --graph 格式。

  • 添加 git describe --contains git describe - 第一父母输出。

  • 可以指定一个缓存目录以节省时间。


git log --decorate adds information about related refs to the log output:

commit 9e895ace5d82df8929b16f58e9f515f6d54ab82d (tag: v3.10-rc7)
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Sat Jun 22 09:47:31 2013 -1000

    Linux 3.10-rc7

This information helps tracking which tag (or branch) contains this commit. When viewing a restricted set of files (say, a subdirectory), there does not have to be a tag for those commits. Is there a way to put a reference to a tag in the log output?

I previously mentioned git describe, but that yields v3.10-rc7-135-g98b6ed0 which is relative to a tag of branch where this change was committed. What I am looking for is a tag name between commits.

For clarity, this is the current situation:

$ git log --decorate --oneline
98b6ed0 (HEAD, origin/master, master) Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
1a506e4 Merge branch 'drm-fixes' of git://people.freedesktop.org/~airlied/linux
578a131 dlci: validate the net device in dlci_del()
11eb264 dlci: acquire rtnl_lock before calling __dev_get_by_name()
...
9e895ac (tag: v3.10-rc7) Linux 3.10-rc7

What I want to have is something like:

98b6ed0 (v3.10-rc7+, HEAD, origin/master, master) Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
1a506e4 (v3.10-rc7+) Merge branch 'drm-fixes' of git://people.freedesktop.org/~airlied/linux
578a131 (v3.10-rc7+) dlci: validate the net device in dlci_del()
11eb264 (v3.10-rc7+) dlci: acquire rtnl_lock before calling __dev_get_by_name()
...
9e895ac (tag: v3.10-rc7) Linux 3.10-rc7

Using git describe's output instead of the commit hash would show something like:

$ git log --decorate --oneline -n4 | awk '{system("git describe " $1 " |tr -d '\''\n'\''");$1="";print}'
v3.10-rc7-135-g98b6ed0 (HEAD, origin/master, master) Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
v3.10-rc7-54-g1a506e4 Merge branch 'drm-fixes' of git://people.freedesktop.org/~airlied/linux
v3.10-rc6-81-g578a131 dlci: validate the net device in dlci_del()
v3.10-rc6-80-g11eb264 dlci: acquire rtnl_lock before calling __dev_get_by_name()
...
v3.10-rc7 (tag: v3.10-rc7) Linux 3.10-rc7

As you can see, older tag names are used as reference point rather than the point where the commit got merged. For illustation purposes, I am using git log --oneline here, but I actually want to use fuller output, e.g. git log -p --stat.

解决方案

The --first-parent parameter of git describe (introduced with git 1.8.4) shows where a commit is derived from. In order to see a relation to the first tag following the commit, use git describe --contains. This options gets very slow (~6 seconds) when you delve deeper in the history though. Available since git 1.5.3.

The command git name-rev can be used to annotate git rev-name and works with --graph and --color too! From its manual page:

Given a commit, find out where it is relative to the local refs. Say somebody wrote you about that fantastic commit 33db5f4d9027a10e477ccf054b2c1ab94f74c85a. Of course, you look into the commit, but that only tells you what happened, but not the context.

Enter git name-rev:

% git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a
33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99~940

Now you are wiser, because you know that it happened 940 revisions before v0.99.

Another nice thing you can do is:

% git log | git name-rev --stdin

This last command appends something to every 40-character SHA-1 hash as shown below (the highlighted part is added by git name-rev).

commit 1ee2dcc2245340cf4ac94b99c4d00efbeba61824 (tags/v3.13-rc1~33)
Merge: 4457e6f 091e066
Author: Linus Torvalds

    Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net

commit b4089d6d8e71a7293e2192025dfa507a04f661c4 (tags/v3.13-rc1~7^2~6^2^2~8)
Author: Felix Fietkau

    rt2x00: fix a crash bug in the HT descriptor handling fix
...
commit dfb6b7c109a7f98d324a759599d1b4616f02c79f (tags/v3.12-rc7~20^2~20^2^2~11)
Author: Stanislaw Gruszka
Date:   Mon Sep 23 04:08:13 2013 +0200

    Revert "rt2x00pci: Use PCI MSIs whenever possible"

    This reverts commit 9483f40d8d01918b399b4e24d0c1111db0afffeb (tags/v3.11-rc1~16^2~103^2^2~111).


An awk script for post-processing git log output is available at https://git.lekensteyn.nl/scripts/tree/git-log-describe.awk (written before I knew of git rev-name). Features:

  • Considers the hash from commit <hash> instead of 40-character hashes (works with --abbrev-commit too).
  • Support for git log --graph format.
  • Adds git describe --contains or git describe --first-parent output.
  • Possibility to specify a cache directory to save time later.

这篇关于我怎样才能用最近的标签来装饰一个git日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆