简体   繁体   中英

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:

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

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.

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

%B: raw body (unwrapped subject and body)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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