I need the date in a special format.
With Git 2.21 (Q1 2019), a new date format "--date=human
" that morphs its output depending on how far the time is from the current time has been introduced.
"--date=auto
" can be used to use this new format when the output is going to the pager or to the terminal and otherwise the default format.
See commit 110a6a1, commit b841d4f (29 Jan 2019), and commit 038a878, commit 2fd7c22 (21 Jan 2019) by Stephen P. Smith (``).
See commit acdd377 (18 Jan 2019) by Linus Torvalds (torvalds
).
(Merged by Junio C Hamano -- gitster
-- in commit ecbe1be, 07 Feb 2019)
Add 'human' date format documentation
Display date and time information in a format similar to how people write dates in other contexts.
If the year isn't specified then, the reader infers the date is given is in the current year.
By not displaying the redundant information, the reader concentrates on the information that is different.
The patch reports relative dates based on information inferred from the date on the machine running the git
command at the time the command is executed.
While the format is more useful to humans by dropping inferred information, there is nothing that makes it actually human.
If the 'relative
' date format wasn't already implemented, then using 'relative
' would have been appropriate.
Add human
date format tests.
When using human
several fields are suppressed depending on the time difference between the reference date and the local computer date.
- In cases where the difference is less than a year, the year field is suppressed.
- If the time is less than a day; the month and year is
suppressed.
check_date_format_human 18000 "5 hours ago" # 5 hours ago
check_date_format_human 432000 "Tue Aug 25 19:20" # 5 days ago
check_date_format_human 1728000 "Mon Aug 10 19:20" # 3 weeks ago
check_date_format_human 13000000 "Thu Apr 2 08:13" # 5 months ago
check_date_format_human 31449600 "Aug 31 2008" # 12 months ago
check_date_format_human 37500000 "Jun 22 2008" # 1 year, 2 months ago
check_date_format_human 55188000 "Dec 1 2007" # 1 year, 9 months ago
check_date_format_human 630000000 "Sep 13 1989" # 20 years ago
Replace the proposed 'auto
' mode with 'auto:
'
In addition to adding the 'human
' format, the patch added the auto
keyword which could be used in the config file as an alternate way to specify the human format. Removing 'auto' cleans up the 'human
' format interface.
Added the ability to specify mode 'foo
' if the pager is being used by using auto:foo
syntax.
Therefore, 'auto:human
' date mode defaults to human
if we're using the pager.
So you can do:
git config --add log.date auto:human
and your "git log
" commands will show the human-legible format unless
you're scripting things.
Git 2.24 (Q4 2019) simplified the code.
See commit 47b27c9, commit 29f4332 (12 Sep 2019) by Stephen P. Smith (``).
(Merged by Junio C Hamano -- gitster
-- in commit 36d2fca, 07 Oct 2019)
Quit passing 'now' to date code
Commit b841d4f (Add human
format to test-tool, 2019-01-28, Git v2.21.0-rc0) added a get_time()
function which allows $GIT_TEST_DATE_NOW
in the environment to override the current time.
So we no longer need to interpret that variable in cmd__date()
.
Therefore, we can stop passing the "now
" parameter down through the
date functions, since nobody uses them.
Note that we do need to make sure all of the previous callers that took a "now
" parameter are correctly using get_time()
.
With Git 2.32 (Q2 2021), "git log --format=...
"(man) placeholders learned %ah
/%ch
placeholders to request the --date=human
output.
See commit b722d45 (25 Apr 2021) by ZheNing Hu (adlternative
).
(Merged by Junio C Hamano -- gitster
-- in commit f16a466, 07 May 2021)
pretty
: provide human date format
Signed-off-by: ZheNing Hu
Add the placeholders %ah
and %ch
to format author date and committer date, like --date=human
does, which provides more humanity date output.
pretty-formats
now includes in its man page:
'%ah
':: author date, human style (like the --date=human
option of
git rev-list
)
pretty-formats
now includes in its man page:
'%ch
':: committer date, human style (like the --date=human
option of
git rev-list
)
--date=iso-strict
: see my answer below – Carbazole--date=(relative|local|default|iso|iso-strict|rfc|short|raw)
, you will also have:--date=(relative-local|default-local|iso-local|iso-strict-local|rfc-local|short-local|raw-local)
– Carbazole