git 日志中缺少换行符 --graph --format=... 文件状态切换?

Missing newline in git log --graph --format=... with file status toggles?

我正在尝试获取包含文件状态信息的 custom-formatted git 日志。不过我把运行换行定位成st运行ge有点问题。

显然,无论何时使用 --format--pretty 参数,通常在文件状态信息之后插入的换行符都会被忽略。这导致有点 hard-to-read 输出像

>> git log -3 --graph --name-status --format=%h:%s
* eee8e08:Second commit With more details in the body.
|
| M hello.txt
* b6146f7:First commit.
|
| A hello.txt
| A world.txt
* 30cb21f:We start from here. Bla bla bla.

在视觉上 file-status 看起来与错误的提交分组。

不需要 --graph 选项,可以通过在格式的开头添加换行符 (%n) 轻松修复它,但是使用 --graph 这只会导致偶数看起来更奇怪,将提交消息从表示图中注释的 * 移开。

>> git log -3 --graph --name-status --format=%n%h:%s
*
| 1868195:Second commit With more details in the body.
|
| M hello.txt
*
| 0f03672:First commit.
|
| A hello.txt
| A world.txt
*
| 033f27f:We start from here. Bla bla bla.

缺少换行符会影响所有 file-status 切换(例如 --name-status--stat--numstat)。

供参考,没有格式化命令,详细消息有更好的换行符定位,

>> git log -3 --graph --name-status
* commit eee8e08d3c892e96228844bcdc6324dc895041af
| Author: me <me@me.org>
| Date:   Wed Nov 22 16:26:58 2017 +0100
|
|     Second commit
|     With more details in the body.
|
| M hello.txt
|
* commit b6146f70b3406508f5b1300c8cda6fd954d3eadd
| Author: me <me@me.org>
| Date:   Wed Nov 22 16:26:58 2017 +0100
|
|     First commit.
|
| A hello.txt
| A world.txt
|
* commit 30cb21f8aba82b30a2f780165533b477cb4555f9
| Author: me <me@me.org>
| Date:   Wed Nov 22 16:26:58 2017 +0100
|
|     We start from here.
|     Bla bla bla.

这使得消息的分组,header和file-status更加清晰。

是否有某种方法可以将 file-status 信息转换为自定义日志格式,而不会丢失将其与上一次提交分开的换行符?


作为参考,输出是在测试存储库中使用脚本创建的 https://pastebin.com/exLswmeR

这应该可以完成工作:git log -3 --graph --name-status --pretty='format:%h:%s%n'

默认情况下,您的格式 git 我猜是使用 tformat。参见 https://git-scm.com/docs/git-log。通过将其设置为 format,新行将正常添加。

我认为它因此更改为 tformat(来自 git 文档):

In addition, any unrecognized string that has a % in it is interpreted
as if it has tformat: in front of it. For example, these two are
equivalent:
$ git log -2 --pretty=tformat:%h 4da45bef
$ git log -2 --pretty=%h 4da45bef