Remove newlines form git commit bodies in git log
Asked Answered
H

0

7

I have following aliases in my .gitconfig to automate my tag annotations (using my git tag-release alias):

[alias]
  lm = log --pretty=format:'(%h) %s%n%w(72,10,10)%b%w(72,0,0)by %an on %ad%n' --date=local --no-merges
  rn = "!f() { git lm \"${1:-$(git describe --abbrev=0 --tags)}\"..\"${2:-$(git rev-parse HEAD)}\"; }; f \"$@\""
  tag-release = "!f() { { echo \"Release $1\n\nChanges:\n\n\"; git rn; } | git tag -a \"$1\" -F -; }; f \"$@\""

My problem is, that because of %w(72,10,10)%b, my commit body is moved 10 spaces to the right and wrapped at 72 characters, which sometimes gives weirdly formatted tag annotations, because the commit messages themselves contain newlines as well. I was wondering if there's a way to get the commit body, replace the newlines and then wrap that at 72 characters with an indentation of 10? Any help is appreciated!

Hardboiled answered 26/9, 2018 at 13:42 Comment(2)
I can get you part way there (removing the new lines); pipe your git log with a sed command... i.e. git log <options> | sed '/^[ \t]*$/d'Annunciator
This is not an answer but, if you can live with the %b format specifier being at the end of the log line, then you will prevent at least some (or even most) of the newlines.Ochrea

© 2022 - 2024 — McMap. All rights reserved.