git日志漂亮格式可以在主题中保留新行吗? [英] Can git log pretty format preserve new lines in subject?

查看:142
本文介绍了git日志漂亮格式可以在主题中保留新行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using this command in a python script to generate an xml file that is later processed by our CI-system:

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>

使用 git log -1 与linebreaks,但与漂亮的格式,他们被省略。有什么办法可以产生像下面这样的输出?

Using git log -1 shows the message with the linebreaks but with the pretty format they are omitted. 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>


推荐答案

git log 的文档告诉我们%s 用于主题,它由构建而成提交消息的标题 (强调我的):

The documentation for git log tells us that %s is for the subject, which is built from the commit message's title (emphasis mine):


尽管不是必需的,使用一个简短的(少于50个字符)行来总结变更,然后是空白行,然后进行更彻底的描述。直到提交消息中的第一个空行的文本被视为提交标题,并且该标题在整个Git中使用。例如, git-format-patch [1] 将提交转换为电子邮件,它使用主题行上的标题和正文中的其余部分。

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

如果要使用整个提交消息,尝试%B 代替:

If you want to use the entire commit message, try %B instead:


%B:原始主体(未包装的主题和身体)

%B: raw body (unwrapped subject and body)

这篇关于git日志漂亮格式可以在主题中保留新行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆