【问题标题】:Custom changelog from git log来自 git log 的自定义更改日志
【发布时间】:2013-11-08 06:58:37
【问题描述】:

我需要帮助才能从 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 命令的初学者。

【问题讨论】:

    标签: git shell sed grep git-log


    【解决方案1】:

    使用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
    

    【讨论】:

    • /title/ 指定该行包含单词“title”。就是总是抢第一排。正如 Robin 所说,可以使用 --format='format:TITLE:%s%n%b' 并创建: git log --format='format: TITLE:%s%n%b'| awk -F= '/TITLE;/ {a=$0} /ISSUE=BZ/ {b=$2 a;gsub(/ +/," ",b);print b}' 但是有没有办法删除“标题:“之后?
    【解决方案2】:

    我将遵循的步骤是:

    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'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-11
      • 2019-12-28
      • 2018-08-08
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 1970-01-01
      相关资源
      最近更新 更多