git commit - setting timestamps into the future

Viewed 18583

I need to make some commits using Git but I would like the timestamp in git-log to be in the future.

How can I do a commit in git that causes a future timestamp to register in the git-log?

6 Answers

You should wait a bit.

Or you can do this:

/tmp/x 604% env GIT_AUTHOR_DATE='Wed Dec 19 15:14:05 2029 -0800' git commit -m 'future!'
[master]: created 6348548: "Future!"
 1 files changed, 1 insertions(+), 0 deletions(-)

/tmp/x 605% git log 

Author: Dustin Sallings <dustin@spy.net>
Date:   Wed Dec 19 15:14:05 2029 -0800

    Future!

Note that there's both an author date and a committer date, so be sure to set the right one (or both).

You can amend the commit, an example with the year 2037:

git commit --amend --date="Wed Feb 16 14:00 2037 +0100"

I tried the year 2038 too but then I got a null value for the date.

If you want to amend a commit with a date "from the future" as in this answer:

git commit --amend --date="Wed Feb 16 14:00 2037 +0100"
  • not use a date after 2016 (Git 2.18 or less)
  • use Git 2.19 (Q3 2018)

See commit 1820703 (21 Aug 2018) by Derrick Stolee (derrickstolee).
(Merged by Junio C Hamano -- gitster -- in commit 1392c5d, 27 Aug 2018)

commit: use timestamp_t for author_date_slab

The author_date_slab is used to store the author date of a commit when walking with the --author-date flag in rev-list or log.
This was added as an 'unsigned long' in 81c6b38 ("log: --author-date-order", June 2013, Git 1.8.4-rc0)

Since 'unsigned long' is ambiguous in its bit-ness across platforms (64-bit in Linux, 32-bit in Windows, for example), most references to the author dates in commit.c were converted to timestamp_t in dddbad7 ("timestamp_t: a new data type for timestamps", April 2017, Git 2.14.0-rc0)

However, the slab definition was missed, leading to a mismatch in the data types in Windows.
This would not reveal itself as a bug unless someone authors a commit after February 2106, but commits can store anything as their author date.

May I ask why you would want to do this?

If you don't want to change your clock, I would suggest creating a script to do the commit and use the Windows Scheduler (or whatever equivalent for your OS) to run the script at the time you want the commit to be.

Related