Home > Blockchain >  git log --pretty=%b but without newline after the body
git log --pretty=%b but without newline after the body

Time:03-11

It’s possible to customize the formatting of git log with --pretty. However I can’t find a way to display the body without trailing newline. Is it possible?

I would like to be able to display my log like this:

dc121234 Add some stuff
2349823f Update things
23498fe2 Add bugs
It’s important to add bug to your code
12398aab Clear thing

With --pretty="%h %s% b" I’m nearly there, but this is what I got:

dc121234 Add some stuff
2349823f Update things
23498fe2 Add bugs
It’s important to add bug to your code

12398aab Clear thing

And if I want to add some more empty space with --pretty="%h %s% b%n" (I added a %n between %s and %b), I get an unwanted double newline after the multilines commit message:

dc121234 Add some stuff

2349823f Update things

23498fe2 Add bugs
It’s important to add bug to your code


12398aab Clear thing

Is there a way to remove the extra trailing newline added after the %b?

CodePudding user response:

--pretty= defaults to tformat, with terminator newlines. --pretty=format:%h\ %s%n%b%-C won't add an extra newline at the end and will eat all the trailing newlines on the body.

  •  Tags:  
  • git
  • Related