How can I extract the commit message (and only/exactly the commit message) of a commit?
git show https://git-scm.com/docs/git-show doesn't seem to have an option for that
I could do git cat-file -p <commit_hash> and then search for the first \n\n and take everything after that until EOF, or I could do git log --format=%B -n 1 <commit_hash> but what is likely going to be forward compatible with future git versions? (of course, there's never a guarantee for that, but there's probably a 'best way' of doing this)
I would avoid trying to parse a file directly; using a git command is likely to provide a backward compatible API even if the underlying data format changes.
I would use avoid
git logbut instead usegit show, which will let you examine a particular commit (instead of a range, whichgit logintends to do). It does, in fact, have an option for that, allowing you to specify custom formatting options.To show only the commit message subject and body, use the
%Bformat and turn off patch display.