如何添加
的输出# Get tag distance $(TAGDIST)
git describe --tags | \
awk '{split($0,TagNameWithTagDist,"-g");
i=split(TagNameWithTagDist[1],TagDist,"-");
print(TagDist[i]);}'
到以下输出?
git log --graph --format=format:'%h - %s + $TAGDIST'
我没有在git-log
文档的“Pretty Formats” section中看到与此值对应的占位符。占位符%d
仅在提交时显示标记名称。
答案 0 :(得分:1)
将以下代码复制为路径中某个目录中名为git-logtagdist
的文件。请注意,它运行缓慢,因为它为每个提交分配一个新的git-describe
进程。您可以通过批量运行git-describe
来加快速度。
#! /usr/bin/env perl
use strict;
use warnings;
use Git;
my $repo = Git->repository;
my @logcmd = (
"log", "--color=always", "--graph",
"--format=format:%h - %s - !!!DISTANCE!!!",
);
my($fh,$ctx) = $repo->command_output_pipe(@logcmd);
if (-t STDOUT) {
my(@pager) = $ENV{GIT_PAGER} || $ENV{PAGER} || ("less", "-R");
open STDOUT, "|-", @pager or die "$0: open: $!";
}
while (<$fh>) {
# e.g., 797166c - Merge branch 'maint' - !!!DISTANCE!!!
s<([0-9a-f]{7,})\b(.+ - )!!!DISTANCE!!!> {
my($sha1,$msg) = ($1,$2);
my $distance;
# e.g., v1.7.9.2-334-g797166c
chomp(my $describe = $repo->command("describe", "--tags", $sha1));
if ($describe =~ /^(.+?)-([0-9]+)-g/) {
$distance = "$2 past $1";
}
else {
$distance = "tagged: $describe";
}
$sha1 . $msg . $distance;
}e;
print;
}
close STDOUT or warn "$0: close: $!";
示例输出:
$ git logtagdist * 9bea2b5 - Git 1.7.11-rc3 - tagged: v1.7.11-rc3 * 3a2c135 - Merge git://github.com/git-l10n/git-po - 17 past v1.7.11-rc2 |\ | * 3482b14 - Merge git://github.com/ralfth/git-po-de - 5 past v1.7.11-rc2 | |\ | | * d7f22ed - l10n: de.po: translate 27 new messages - 3 past v1.7.11-rc2 | * | 6cb4571 - l10n: Update po/vi.po to v1.7.11.rc2.2.gb694fbb - 3 past v1.7.11-rc2 | |/ | * b694fbb - l10n: zh_CN.po: translate 27 new messages - 2 past v1.7.11-rc2 | * 7256fd7 - l10n: Update git.pot (27 new, 1 removed messages) - 1 past v1.7.11-rc2 * | 73a6e3c - Merge branch 'mm/api-credentials-doc' - 11 past v1.7.11-rc2