Git is a little lax on properly distinguishing between plumbing and porcelain. The advice to use plumbing commands in scripts is good, but sometimes a command—such as git log
—doesn't have an appropriate plumbing variant, but does have options that make it "plumby", if I can make up a word.
In this case, an appropriate command is (edited, 21 Mar 2019, per comment from Josh):
git -c log.showSignature=false log --pretty=format:%ad --no-walk <hash>
(or the same with %cd
as the format directive for committer date; add various date formatting options, to git log
itself, or as %aD
for instance, to change the date format). Nothing exactly promises that git log
might not add new features, such as the log.decorate
setting, that might disrupt this, and Git should get with itself and add --porcelain
options to the commands that behave like git status
does. (Note that git status
now has --porcelain
and --porcelain=v2
, both of which convert it to plumbing. Don't ask me why this isn't spelled --plumbing
...)
git log --pretty=format:%aD | head -1
orgit show --format="format:%aD" --no-patch HEAD
. – FaradmeterMon, 8 Oct 2018
for the date in the%aD
format, but I don't know whether I can reasonably expect that some future version won't produceMon, 08 Oct 2018
for the same commit. – Hamnet%aD
format is specified as "author date, RFC2822 style", the format should remain the same. To get another fixed format, you could use%aI
or add a dedicated--date=raw
. Neither of these should change with a larger probability than the "plumbing" version. – Faradmeter%aI
will change, but since the git docs explicitly say that porcelain commands are subject to change and shouldn't be used in scripts (except of course in cases where they offer a--porcelain
option), I would prefer not to rely on second-guessing their future development. – Hamnet