【问题标题】:Can git log pretty format preserve new lines in subject?git log pretty format 可以保留主题中的新行吗?
【发布时间】:2016-06-06 18:34:41
【问题描述】:

我在 python 脚本中使用这个命令来生成一个 xml 文件,稍后由我们的 CI 系统处理:

git log -1 --date=iso --pretty=format:"<logentry revision=\"%h\" scm=\"git\">%n<author>%an</author>%n<date>%ad</date>%n<msg>%s</msg>%n"

它产生以下格式的输出

<logentry revision="1e370f5" scm="git">
<author>Johan Govers</author>
<date>2016-02-24 13:11:15 +0100</date>
<msg>PP-204 Try out git PP-207 New build script * Add missing kind="file" to path nodes in changes xml file.</msg>

使用git log -1 会显示带有换行符的消息,但使用漂亮的格式会省略它们。有没有办法产生如下输出?

<logentry revision="1e370f5" scm="git">
<author>Johan Govers</author>
<date>2016-02-24 13:11:15 +0100</date>
<msg>PP-204 Try out git 
PP-207 New build script 
* Add missing kind="file" to path nodes in changes xml file.</msg>

【问题讨论】:

    标签: python git


    【解决方案1】:

    documentation for git log 告诉我们%s 用于主题,它是从commit message's title(强调我的)构建的:

    虽然不是必需的,但最好在提交消息的开头使用一个简短(少于 50 个字符)行来总结更改,然后是一个空行,然后是更详尽的描述。 提交消息中第一个空白行之前的文本被视为提交标题,并且该标题在整个 Git 中使用。例如,git-format-patch[1] 将提交转换为电子邮件,它使用主题行中的标题和正文中的其余提交。

    如果您想使用整个提交消息,请尝试使用%B

    %B:原始正文(展开的主题和正文)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 2019-07-28
      相关资源
      最近更新 更多