如何在git commit主体的每一行前面加上一个字符

问题描述 投票:3回答:1

我们的代码审查工具将Markdown用于CR描述。我想自动化通过从git commits获取信息来编写这些描述已审核。

说我有一个带有以下主题和内容的git commit:

This is the subject line

This is a long paragraph spanning multiple lines wrapped to 80
characters. 

This is a second paragraph.

我想创建一个git日志格式化程序,从这次提交:

`<commit short hash>` - This is the subject line

> This is a long paragraph spanning multiple lines wrapped to 80
> characters.
> 
> This is a second paragraph.

我已经尝试了以下命令来产生此输出,但是我找不到将>附加到正文的每一行的方法

$ git log --format='`%h` - %s%n%n> %b%n' 'HEAD^..HEAD'
`e8aa4cf` - This is the subject line

> This is a long paragraph spanning multiple lines wrapped to 80
characters.

This is a second paragraph.

我尝试的另一种选择是使用w(80,2,2)垫住身体,但这是在每行上也缺少>

$ git log --format='`%h` - %s%n%n>%w(80,2,2)%b%n' 'HEAD^..HEAD'
`e8aa4cf` - This is the subject line

>  This is a long paragraph spanning multiple lines wrapped to 80 characters.

  This is a second paragraph.

可以使用git log --format='X'完成吗?

git git-log
1个回答
0
投票

看上去git log --format不允许更改正文。

作为替代,可以使用sed插入填充>,例如:

git log --pretty=format:'`%h` - %s%n%w(80,8,2)%b' | sed 's/^        /> /' | sed -z 's/\n\n>/\n>\n>/g'
© www.soinside.com 2019 - 2024. All rights reserved.