log.log I want a line break after %s" /> log.log I want a line break after %s" /> log.log I want a line break after %s"/>

git log with line break when exported to text file

14.5k Views Asked by At

How do I add a line break for my custom git log?

git log --pretty=tformat:"%ai %s" > log.log

I want a line break after %s

7

There are 7 best solutions below

2
OtherDevOpsGene On BEST ANSWER

You can use %n as a new line:

git log --pretty=tformat:"%ai %s%n" > log.log
1
pjz On

The quotes will save you - just put the close quote on the next line, like:

git log --pretty=tformat:"%ai %s
" >log.log

and it should work.

Alternately, under the PRETTY FORMATS heading of git log --help it lists:

       ·   %m: left, right or boundary mark

       ·   %n: newline

       ·   %%: a raw %

Though apparently a 'newline' is a unix newline so on windows you'll want to use the direct hex codes like:

git log --pretty=tformat:"%ai %s%x10%x13" >log.log
0
Hamid Shahid On

The reason is that git uses LF as a separator while notepad and most windows application uses CRLF. The following script enabled me to produce a file with all changes.

del files.txt >nul 2>nul
git show --pretty="format:" --name-only HEAD > changes.txt
for /F "tokens=*" %%A in ('type "changes.txt"') do echo %%A >> files.txt
0
Tom Margrave On

For those making Windows batch files with git remember to convert single % to double %%. Also add hex for Carriage Return and Line feed

for example

git log --pretty=tformat:"%ai %s%x0D%x0A" >log.log

converted for window batch file

git log --pretty=tformat:"%%ai %%s%x0D%x0A" >log.log
0
Naughton On

Pjz's answer is not quite right for Windows, but with a little playing around I got it to work. The 10 and 13 characters needed to be reversed, and they needed to be in proper hex format:

git log --pretty=tformat:"%ai %s%x0D%x0A" >log.log
0
Bart Robinson On

The other answers for Windows result in extra 0x0A characters in the file. Git already appends 0x0A to each log entry, so you just need to add the missing 0x0D:

git log --pretty=tformat:"%ai %s%x0D" >log.log

Or inside a batch file:

git log --pretty=tformat:"%%ai %%s%%x0D" >log.log
0
WicCaesar On

I was in a similar situation just now, I wanted to add a line break because cat -e would mess with the formatting when running the command in a bash script. I had tried the suggestions in this page and others more, but what really solved my problem was just removing format:. Typing only git log --pretty="%H" adds a normal line break after the last result.