Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ugultopu/3f09013d30f225eddcdc7b0fc9c92cb3 to your computer and use it in GitHub Desktop.
Save ugultopu/3f09013d30f225eddcdc7b0fc9c92cb3 to your computer and use it in GitHub Desktop.

Update

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 with GIT_COMMITTER_DATE="2017-02-02".
  • Use "author date" (%ad) instead of the "committer date" (%cd) in your git-log invocation, so that the date you provided to git-commit invocation via the --date argument will be reflected in git-log output, since the date provided to git-commit invocation via the --date argument represents the "author date", as opposed to the "commiter date".

Original Article

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment