有谁知道为什么“之前”包括完成日期?
Does any know why `before` include finish date?
有人知道为什么 before
包括完成日期吗?
日期2021-07-01 14:13
实际上是在2021-07-01
之后
为什么结果是错误的?
git 版本为 2.32.0
注意日期过滤器使用提交日期时间,而不是作者日期时间。
尽管没有记录,如 中所述并通过我的有限测试证实,但令人惊讶的是,似乎所有日期过滤器在未指定时间时都指的是当前时间在您的客户端机器上的那一天!请注意,如果您希望覆盖该时间,您可以指定一个时间:
git log --before=2021-07-02T23:59:59
(当天结束)
或
git log --before=2021-07-02T00:00:00
(一天的开始)
下面是我的测试脚本。它生成一个新的回购协议,其中包含一个空提交,提交者日期从 2 天前减去 1 分钟。 (因此从现在开始的 1 分钟提交将恰好是 2 天前。)然后脚本循环一分钟,每 10 秒打印一次当前时间,以及使用 --before
和 [=14 的日志=] 选项。起初 --before 不显示任何内容,--after 显示提交,但是一分钟后,一旦当前时间超过提交日期,日志就会翻转:
#!/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
如果您没有指定截止时间,它会使用当前的挂钟,所以 --before=yesterday
在下午 5 点询问意味着昨天下午 5 点之前。如果要指定午夜,请添加 T00:00
、--before=yesterday.T00:00
。我认为这足够令人惊讶,可以算作一个成熟的疣,就像 find
的大小行为一样。不幸的是,这被核心命令使用,即所谓的“管道”,并且 Git 已明确向脚本编写者承诺他们的行为以及此日期解析 wart 不会改变。
编辑:试试这个:
unset head; for h in {0..23}; do
head=$( GIT_COMMITTER_DATE=`date -d yesterday\ T$h:00` \
git commit-tree ${head+-p $head} -m - @: )
done
git log -1 --pretty=fuller $head
git log -1 --pretty=fuller --before=yesterday $head
你会看到 before=yesterday
选择提交时间戳在当前挂钟之前的那个。
有人知道为什么 before
包括完成日期吗?
日期2021-07-01 14:13
实际上是在2021-07-01
为什么结果是错误的?
git 版本为 2.32.0
注意日期过滤器使用提交日期时间,而不是作者日期时间。
尽管没有记录,如
git log --before=2021-07-02T23:59:59
(当天结束)
或
git log --before=2021-07-02T00:00:00
(一天的开始)
下面是我的测试脚本。它生成一个新的回购协议,其中包含一个空提交,提交者日期从 2 天前减去 1 分钟。 (因此从现在开始的 1 分钟提交将恰好是 2 天前。)然后脚本循环一分钟,每 10 秒打印一次当前时间,以及使用 --before
和 [=14 的日志=] 选项。起初 --before 不显示任何内容,--after 显示提交,但是一分钟后,一旦当前时间超过提交日期,日志就会翻转:
#!/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
如果您没有指定截止时间,它会使用当前的挂钟,所以 --before=yesterday
在下午 5 点询问意味着昨天下午 5 点之前。如果要指定午夜,请添加 T00:00
、--before=yesterday.T00:00
。我认为这足够令人惊讶,可以算作一个成熟的疣,就像 find
的大小行为一样。不幸的是,这被核心命令使用,即所谓的“管道”,并且 Git 已明确向脚本编写者承诺他们的行为以及此日期解析 wart 不会改变。
编辑:试试这个:
unset head; for h in {0..23}; do
head=$( GIT_COMMITTER_DATE=`date -d yesterday\ T$h:00` \
git commit-tree ${head+-p $head} -m - @: )
done
git log -1 --pretty=fuller $head
git log -1 --pretty=fuller --before=yesterday $head
你会看到 before=yesterday
选择提交时间戳在当前挂钟之前的那个。