git - 有谁知道为什么“之前”包括完成日期?
解决方案
请注意,日期过滤器使用提交日期时间,而不是作者日期时间。
尽管没有记录,如jthill 的回答中所述并通过我的有限测试得到证实,但令人惊讶的是,当未指定时间时,所有日期过滤器似乎都是指客户端计算机上的当前时间!请注意,如果您想覆盖它,您可以指定一个时间:
git log --before=2021-07-02T23:59:59
(一天结束)
或者
git log --before=2021-07-02T00:00:00
(一天的开始)
下面是我的测试脚本。它会生成一个新的仓库,其中包含一个空提交,提交者日期为 2 天前减去 1 分钟。(所以从现在开始的 1 分钟提交将恰好是 2 天前。)然后脚本循环一分钟,每 10 秒打印一次当前时间,以及使用--before
和--after
选项的日志。起初 --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
推荐阅读
- ubuntu - Google Compute Engine VM 上的 Ubuntu do-release-upgrade
- c# - C#只查询xslt的父节点
- python-3.x - ModuleNotFoundError:没有名为“settings_sensitive”的模块
- firebase - Firebase Cloud Functions 与 Firebase 移动原生 SDK
- docker - docker容器启动后是否可以增加内存限制?
- python - 网页上更快的 SQL 结果(Python 3.6、Flask、Pymssql)
- javascript - 使用 path.centroid() 找不到路径对象的中心
- python-3.x - python web开发的前置步骤?
- javascript - 在javascript中出现“预期未定义”错误
- php - 没有通过 Google_Service_YouTube 进行直播(google/apiclient)