Git: How to list specific trailers (footers) in git-log format?
Asked Answered
C

1

17

Given the following example git commit message:

My commit message summary

Some more body in this message...

Signed-off-by: My name <[email protected]>
Issue: MYPROJ-123

I can now parse these 'trailers' (key/value parameters in the footer) with recent Git versions (2.14+) using git interpret-trailers --parse. This appears integrated into git-log formatting options as well, e.g.:

git log --format="%h %s %(trailers)"

However, it shows me all trailers, including the line breaks.

Would it be possible to limit this to the value(s) of a single trailer token? Ideally, what I'd like to accomplish is something like this as a git-log line, showing the value of the Issue token only:

0123abcd My commit message summary MYPROJ-123
Cherise answered 24/11, 2017 at 14:54 Comment(0)
D
15

This is possible using trailers options. Following your example the command line would be:

git log --format="%h %s %(trailers:key=Issue,valueonly)"
Darryl answered 26/2, 2020 at 23:7 Comment(2)
Thanks! My git version 2.28.0 tends to include a superfluous newline as part of the trailer value, however. Fixed with git log --format="%h %s %(trailers:key=Issue,valueonly,separator=%x2C )"Cherise
Git version 2.34.1 also puts in an unwanted newlineZadoc

© 2022 - 2024 — McMap. All rights reserved.