简体   繁体   English

git log漂亮格式可以保留主题中的新行吗?

[英]Can git log pretty format preserve new lines in subject?

I'm using this command in a python script to generate an xml file that is later processed by our CI-system: 我在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"

It produces output on the following format 它以下列格式生成输出

<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>

Using git log -1 shows the message with the linebreaks but with the pretty format they are omitted. 使用git log -1显示带有换行符的消息,但是它们的格式相同,省略了它们。 Is there any way to produce an output like the following? 有没有办法产生如下的输出?

<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>

The documentation for git log tells us that %s is for the subject , which is built from the commit message's title (emphasis mine): git log文档告诉我们%s是针对主题的 ,它是根据提交消息的标题构建 (强调我的):

Though not required, it's a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. 虽然不是必需的,但最好使用一个简短(小于50个字符)的行来概括更改,然后是空白行,然后是更详尽的描述。 The text up to the first blank line in a commit message is treated as the commit title , and that title is used throughout Git. 提交消息中第一个空白行的文本被视为提交标题 ,并且该标题在整个Git中使用。 For example, git-format-patch[1] turns a commit into email, and it uses the title on the Subject line and the rest of the commit in the body. 例如, git-format-patch [1]将提交转换为电子邮件,它使用Subject行上的标题和正文中的其余提交。

If you want to use the entire commit message, try %B instead: 如果要使用整个提交消息,请尝试使用%B

%B: raw body (unwrapped subject and body) %B:生体(未包裹的主体和身体)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM