Reputation: 1205
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
Upvotes: 24
Views: 16192
Reputation: 15
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.
Upvotes: 0
Reputation: 1104
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
Upvotes: 4
Reputation: 129
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
Upvotes: 8
Reputation: 11
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
Upvotes: 1
Reputation: 4616
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
Upvotes: 4
Reputation: 43057
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
Upvotes: 2
Reputation: 7451
You can use %n
as a new line:
git log --pretty=tformat:"%ai %s%n" > log.log
Upvotes: 26