我们的代码审查工具将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 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'