git:如何显示自 "the last time it was 5AM" 以来的提交

git: how to show commits since "the last time it was 5AM"

我正在尝试制作一个别名,使用时会显示自凌晨 5 点以来的所有提交。首先,我找到了 this Stack Overflow answer 这让我走了这么远:

git log --since="5am"

起初似乎正是我需要的,只是在使用了一段时间后,我注意到如果我在 05:0023:59 之间的任何时间执行它,我会得到所有从早上 5 点开始的同一天提交的所有提交都如预期的那样,但是如果我在 00:0004:59 之间的任何时间执行它,我没有得到任何提交,甚至没有我提交的提交凌晨 12 点以后。

所以我想使用像 --since 这样的时间有点等同于 "give me all the commits that were literally committed today AND after 5 AM"。我想要的更像是"give me all the commits that were committed since the last time it was 5 AM, be it today or yesterday"。例如,如果今天我在上午 9 点进行提交,我希望能够在当天剩余时间以及明天凌晨 12 点到凌晨 5 点的结果中看到它。

有办法实现吗?

谢谢:)

我认为您可以通过在 since 参数中测试当前时间来解决这个问题。这样的事情可能会奏效。 (假设 bash shell。)

git log --since="5am$(if test $(date +%k) -lt 5; then echo ' yesterday'; fi)"