Set the author date
The
--date
option allows to specify (or more accurately override) the commit's so-called
author date. The author date is typically interpreted as the timestamp when a
commit object was first added to a
repository.
In order to demonstrate this, a git repository is created:
$ mkdir repo
$ cd repo
$ git init
Then, three commit objects are created, each with an arbitrary author date:
'one' > file.txt
git add file.txt
commit file.txt -m "add numbers.txt" --date '2021-01-01 11:12:13'
'two' > file.txt
git commit file.txt -m "Version 2" --date '2021-02-02 12:22:20'
'three' > file.txt
git commit file.txt -m "Version 3" --date '2021-03-13 03:33:30'
Finally, the file's log is inspected, using a format that just prints the author date (%ai
) and the commit message's (%s
) subject:
git log --format='%ai %s' --reverse file.txt
The command prints
2021-01-01 11:12:13 +0100 add numbers.txt
2021-02-02 12:22:20 +0200 Version 2
2021-03-13 03:33:30 +0300 Version 3
Cleaning up:
cd ..
rmdir -r -force repo