How can I decorate a git log with its nearest tag?

前端 未结 2 1539
闹比i
闹比i 2021-02-08 03:50

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

commit 9e895ace5d82df8929b16f58e9f515f6d54ab82d (tag: v3.10-rc7)
Author: L         


        
2条回答
  •  暖寄归人
    2021-02-08 04:27

    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 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.

提交回复
热议问题