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

标签 git git-log

我们的代码审查工具使用 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/

相关文章:

git - 在 git diff 中避免 "No newline at end of file"

git log 不从 Mac 终端的第一行开始

git - 配置 git log 默认使用 mailmap

git - Git日志的-r选项有什么作用?

git log 显示两个分支之间的不同提交,包括共同祖先

git - 为什么 git log 不显示移动文件的历史记录,我该怎么办?

git - 查看未推送到远程的本地提交的 git 更改/差异

sql - 我应该把 .mdf 和 .ldf 文件放在哪里才能通过 git 共享 SQL 脚本

git - 将文件移至 LFS 后如何从 git 数据库中删除该文件?

ruby - 如何使用 webhooks 从 Gitlab 推送到 Github