我需要帮助来创建GIT日志的自定义格式化更改日志。

这是git日志看起来像我们编写的方式。

commit 2f5719d373e284e4473a5a3f229cbf163f6385fe
Author: Adrian <adrian@mycompany.com>
Date:   Tue Nov 5 17:23:51 2013 +0100

    This is the title of the commit

    Some description about the commit, row 1
    Some description about the commit, row 2
    Some description about the commit, row 3

    ISSUE=BZ1020
    ISSUE=BZ1022        
    Change-Id: I1e15e12da28692e09c377c084dc439fec1d58f4c

我想要的格式是提取 title 行和 ISSUE=BZ 行并创建一个不错的更改日志。我想要这样的东西,首先使用问题编号,然后再用标题。我也想支持几个 ISSUE=BZ 标签如果有人在一个提交中修复了几个错误。当然,并非所有的提交都包含修复的错误,因此我想完全省略这些提交。

BZ1020 This is the title of the commit
BZ1022 This is the title of the commit

到目前为止,我设法提取了所有问题,但没有此命令的标题:

git log <old version>..HEAD | grep -i 'ISSUE=BZ' | sed 's/.*=//g'

生产:

BZ1020
BZ1022

有什么想法如何进行?我必须告诉你,我是一个初学者 sed 命令。

有帮助吗?

解决方案

使用 awk 您可以这样做:

git log <old version>..HEAD | awk -F= '/title/ {a=$0} /ISSUE=BZ/ {b=$2 a;gsub(/ +/," ",b);print b}'
BZ1020 This is the title of the commit
BZ1022 This is the title of the commit

其他提示

我将遵循的步骤是:

  1. 使用自定义格式仅输出标题(带有 TITLE: 预先)和身体
  2. 编写一个寻找的SED脚本 TITLE:, ,存储它,然后寻找 ISSUE=, ,并输出两者

因此,这是我在有限的时间内提出的。这并不是您要求的,但这是一个起点:

git log --format='format:TITLE:%s%n%b'|sed -ne '/^TITLE:/h;s/ISSUE=//;t found;b;: found;G;p'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top