I need a plumbing command to print the commit message of one given commit - nothing more, nothing less.
8 Answers
It's not "plumbing", but it'll do exactly what you want (%B represents the whole commit message):
$ git log --format=%B -n 1 <commit>
If you absolutely need a "plumbing" command (not sure why that's a requirement), you can use rev-list:
$ git rev-list --format=%B --max-count=1 <commit>
Although rev-list will also print out the commit sha (on the first line) in addition to the commit message.
9 Comments
%B is a correct specifier (at least, in Git 1.7.2, not sure when it was added).%B was added sometime after 1.7.1 (probably in 1.7.1.1).%s instead of %B because it prints only the commit message subject, not the body (expanded description) if one is suppliedgit log appears slowergit show is more a plumbing command than git log, and has the same formatting options:
git show -s --format=%B SHA1
8 Comments
%s instead of %B.let xs = [123]; for (x in xs) { show(x) }", but it's simpler and quicker to just do show(123).rev-list has a max-count option and show doesn't that rev-list is iterating over the whole tree or doing something computationally intensive. But you can't make such assumptions on the internal workings based on the public API. git show is a porcelain command, without having dug deep, I'm assuming it's using the exact same mechanics as rev-list as well as a whole bunch of other user-friendly operations that slow it down. Porcelain commands are not optimized for speedNot plumbing, but I have these in my .gitconfig:
lsum = log -n 1 --pretty=format:'%s'
lmsg = log -n 1 --pretty=format:'%s%n%n%b'
That's "last summary" and "last message". You can provide a commit to get the summary or message of that commit. (I'm using 1.7.0.5 so don't have %B.)
1 Comment
I started to use
git show-branch --no-name <hash>
It seems to be faster than
git show -s --format=%s <hash>
Both give the same result
I actually wrote a small tool to see the status of all my repos. You can find it on github.
1 Comment
Print commit message using git-rev-list
git-rev-list is the plumbing command that let's you print the message of a commit.
Use it like this.
git rev-list --max-count=1 --no-commit-header --format=%B <commit>
--max-count=1: we're just interested in one commit--no-commit-header: Don't show the default commit header--format=%B: show message (subject%s+%n%n+ body%b)<commit>: asha,HEAD,branch-name,tag-name,branch1...branch2etc.
It's a lot faster than git log or git show.
3 Comments
tail +3.--no-commit-header option to rev-list. If you need use sed, you can use sed '/^commit [0-9a-f]\{40\}$/d' (stackoverflow.com/a/68514358/10807837)
git show -s --oneline <commit>Plumbing and Porcelain This book covers primarily how to use Git with 30 or so subcommands such as checkout, branch, remote, and so on. But because Git was initially a toolkit for a version control system rather than a full user-friendly VCS, it has a number of subcommands that do low-level work and were designed to be chained together UNIX-style or called from scripts. These commands are generally referred to as Git’s “plumbing” commands, while the more user-friendly commands are called “porcelain” commands.