git - 如何在 git commit 正文的每一行前面添加一个字符
问题描述
我们的代码审查工具使用 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.
我已尝试使用以下命令来生成此输出,但我找不到将其>
添加到正文每一行的方法
$ 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
,可用于插入 padding >
,例如:
git log --pretty=format:'`%h` - %s%n%w(80,8,2)%b' | sed 's/^ /> /' | sed -z 's/\n\n>/\n>\n>/g'
推荐阅读
- excel - 从 xslx golang 中检索 CellRange
- docker - Docker 容器在 `docker start` 上立即退出
- javascript - const errorDetails = { message: err.message, status: err.status, stackHighlighted: err.stack.replace(/[a-z_-\d]+.js:\d+:\d+/gi, '$&') };
- hyperledger-fabric - 在 fabric-samples 中使用 couchdb 选项时,无法在 Hyperledger Fabric 1.3 中实例化链代码
- ios - 运行命令 shell 脚本 [cp] embed pods framework' 0.2 seconds Command PhaseScriptExecution failed with a nonzero exit code
- jasper-reports - 应用条件格式时子报表周围出现不需要的边框
- python - POST 请求方法在 Django Rest 框架中不起作用
- node.js - 如何使用带有 mocha 的 await 和 ESM 获取 selenium 驱动程序?
- java - 使用表达式委托而不是 Java 类有什么好处?
- dart - 在 Flutter 中定义 const 级别的类