1

我需要帮助才能从 git log 创建自定义格式的更改日志。

这是 git log 看起来像我们编写它的方式。

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命令的初学者。

4

2 回答 2

0

我将遵循的步骤是:

  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'
于 2013-11-08T07:08:23.363 回答
0

使用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
于 2013-11-08T07:30:49.793 回答