我们的代码审查工具使用 Markdown 作为 CR 描述。我想自动化
通过从 git 提交中获取信息来编写这些描述
审查。
假设我有一个带有以下主题和正文的 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 log 格式化程序,它产生以下输出
这次提交:
`<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.
我已尝试使用以下命令来生成此输出,但找不到
前置
>
的方法 body 的每一根线条$ 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)
垫 body ,但这是还缺少
>
在每一行上。$ 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'
关于git - 如何在 git commit 主体的每一行前面添加一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60093746/