Nope, my bad. It is not silently ignored or something. In fact, the second line among the output after a commit shows the date, and it is in fact the date specified:
$ git commit -m "Add another commit" --date="2017-02-02"
[consumer_class 64a329e] Add another commit
Date: Thu Feb 2 09:42:54 2017 -0500
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 dummy.txt
$
The problem was, in my invocation of git log
, which I invoked as:
git log --graph --all --pretty=format:"%C(auto)%h %cd%d %s" --date=short
I was using "committer date" (%cd
), instead of the "author date" (%ad
). The --date
option in git-commit
sets only the "author date". It does not set the "committer date". I guess the only way to change the "committer date" is to set the GIT_COMMITTER_DATE
environment variable.
Hence, the answer is:
- Either set the "committer date" by preceding your
git-commit
invocation withGIT_COMMITTER_DATE="2017-02-02"
. - Use "author date" (
%ad
) instead of the "committer date" (%cd
) in yourgit-log
invocation, so that the date you provided togit-commit
invocation via the--date
argument will be reflected ingit-log
output, since the date provided togit-commit
invocation via the--date
argument represents the "author date", as opposed to the "commiter date".
This is a problem because you will think that your commit will have the indicated date, whereas it will have the date the commit command is run, since Git has silently ignored the "malformed" date argument. This is something to be aware of.