Does any know why before
include finish date?
The date 2021-07-01 14:13
actually is after 2021-07-01
Why results are wrong?
git version is 2.32.0
Note the date filters use the commit datetime, not the author datetime.
Although it isn't documented, as noted in jthill's answer and confirmed by my limited testing, surprisingly, it appears that all the date filters, when a time is not specified, refer to the current time of the day on your client machine! Note you can specify a time if you wish to override that:
git log --before=2021-07-02T23:59:59
(end of the day)
or
git log --before=2021-07-02T00:00:00
(beginning of the day)
Below is my test script. It generates a new repo with one empty commit with a committer date from 2 days ago minus 1 minute. (So that 1 minute from now the commit will be exactly 2 days ago.) Then the script loops for a minute and every 10 seconds it prints out the current time, as well as the log using --before
and --after
options. At first --before doesn't show anything and --after shows the commit, but after a minute the logs flip once the current time surpasses that of the commit date:
#!/bin/bash
# create a test repo
git init
echo ""
# create a date which is 2 days ago minus 1 minute
var1=$(date --date '-2879 min')
# create a date that is the first date in only YYYY-MM-DD format
var2=$(date -d "$var1" +%F)
# show the variables
echo "var1=$var1"
echo "var2=$var2"
echo ""
# create an empty commit with a committer date set to 2 days ago minus 1 minute
GIT_COMMITTER_DATE=$var1 git commit --allow-empty -m 'Create an empty commit'
# display the log; there should only be 1 commit
git log --pretty=fuller
echo ""
# Every 10 seconds for 70 seconds, display the log before 2 days ago without a time specified.
# As soon as the current time passes the time of the commiter_date on the commit, the log will show.
for (( x=1; x<=8; x++ ))
do
echo "Current time: $(date)"
echo "Output of: 'git log --before=$var2':"
git log --before=$var2
echo ""
echo "Output of: 'git log --after=$var2':"
git log --after=$var2
echo ""
sleep 10
done