gpt4 book ai didi

git - 如何使用 git log --since 产生可靠的结果

转载 作者:行者123 更新时间:2023-12-05 06:00:37 27 4
gpt4 key购买 nike

我需要运行 git log 来显示特定日期和时间之后的所有提交,并且不遗漏任何提交,并且没有运行 git log 显示所有 提交,因为后者太慢(因为这应该在 git IMO 中工作)。

但是,您将其标记为重复项之前,请考虑我已尽可能仔细地阅读以下所有内容:

  1. What is the format for --date parameter of git commit
  2. git log --since=<date> options
  3. Strange behavior from git log --since
  4. How does git log --since count?

这是我尝试过的:

$ git --version
git version 2.31.1
$ date
Tue May 18 08:55:45 PDT 2021
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='2021-04-01' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='2021-04-01 00:00' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='2021-04-01 00:00:00' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='2021-04-01T00:00:00' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='1 week ago' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='2 weeks ago' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='3 weeks ago' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='4 weeks ago' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' --since='666 weeks ago' | grep 2021-04- | tail -1
2021-04-23 11:51:30 -0700 4 weeks ago 76044d3f08087add08ad1012ae1ee9a569679268
$ git log --date=local --format='%ad %<(20)%ar %H' --since='2021-04-01' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='2021-04-01 00:00' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='2021-04-01 00:00:00' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='2021-04-01T00:00:00' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='1 week ago' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='2 weeks ago' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='3 weeks ago' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='4 weeks ago' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='666 weeks ago' | grep 2021-04- | tail -1
$ git log --date=local --format='%ad %<(20)%ar %H' --since='666 weeks ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='2021-04-01' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='2021-04-01 00:00' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='2021-04-01 00:00:00' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='2021-04-01T00:00:00' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='1 week ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='2 weeks ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='3 weeks ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='4 weeks ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ad %<(20)%ar %H' --since='666 weeks ago' | grep 2021-04- | tail -1
$ git log --date=iso-local --format='%ad %<(20)%ar %H' | grep 2021-04- | tail -1
2021-04-01 00:00:13 -0700 7 weeks ago 657fa6a40cfd93c6d48a8aee4cc8190df753f6d7
$ git log --date=default --format='%ci %<(20)%ar %H' --since='2021-04-01' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='2021-04-01 00:00' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='2021-04-01 00:00:00' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='2021-04-01T00:00:00' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='1 week ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='2 weeks ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='3 weeks ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='4 weeks ago' | grep 2021-04- | tail -1
$ git log --date=default --format='%ci %<(20)%ar %H' --since='666 weeks ago' | grep 2021-04- | tail -1
2021-04-23 18:51:30 +0000 4 weeks ago 76044d3f08087add08ad1012ae1ee9a569679268
$ git log --date=iso-local --format='%ci %<(20)%ar %H' | grep 2021-04- | tail -1
2021-04-01 00:00:13 -0700 7 weeks ago 657fa6a40cfd93c6d48a8aee4cc8190df753f6d7
$

我很困惑为什么我得到关于提交 76044d3f08087add08ad1012ae1ee9a569679268 的输出,而其他 --date=something 变体不显示任何输出。当然无论如何它都是错误的输出。

令人费解。

这是我不想经常求助的缓慢解决方法:

$ git log --date=iso-local --format='%ad %<(20)%ar %H' | grep 2021-04- | tail -1
2021-04-01 00:00:13 -0700 7 weeks ago 657fa6a40cfd93c6d48a8aee4cc8190df753f6d7
$

在后一个命令中,Git 正在转储整个提交历史,只是为了让我必须过滤掉我正在寻找的结果。在这种情况下,git log 很慢,因为我的 git 存储库很大:

$ git log --date=iso-local --format='%ad %<(20)%ar %H' | wc -l
344841

我在这里做错了什么?还是 --since 选项有缺陷?

最佳答案

torek评论:

Since committer dates can be spoofed or incorrect, this can cut off a traversal incorrectly.

不再是,自 Git 2.37(2022 年第 3 季度)以来:

在 2.37 之前," git log --since=X "( man ) 在看到早于 X 的提交时停止遍历.
但它背后可能有比 X 更年轻的提交。当使用错误的时钟创建提交时。

新选项 --since-as-filter添加到不停地挖掘,而是过滤掉时间戳早于X的提交.

参见 commit 9669778 (2022 年 4 月 23 日)Miklos Vajna ( vmiklos ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 6f24da6,2022 年 5 月 20 日)

log: "--since-as-filter" option is a non-terminating "--since" variant

Signed-off-by: Miklos Vajna

The "--since=<time>" option of "git log"(man) limits the commits displayed by the command by stopping the traversal once it sees a commit whose timestamp is older than the given time and not digging further into its parents.

This is OK in a history where a commit always has a newer timestamp than any of its parents'.
Once you see a commit older than the given <time>, all ancestor commits of it are even older than the time anyway.

It poses, however, a problem when there is a commit with a wrong timestamp that makes it appear older than its parents.
Stopping traversal at the "incorrectly old" commit will hide its ancestors that are newer than that wrong commit and are newer than the cut-off time given with the --since option.
--max-age and --after being the synonyms to --since, they share the same issue.

Add a new "--since-as-filter" option that is a variant of "--since=<time>".
Instead of stopping the traversal to hide an old enough commit and its all ancestors, exclude commits with an old timestamp from the output but still keep digging the history.

Without other traversal stopping options, this will force the command in "git log" family to dig down the history to the root.
It may be an acceptable cost for a small project with short history and many commits with screwy timestamps.

It is quite unlikely for us to add traversal stopper other than since, so have this as a --since-as-filter option, rather than a separate --as-filter, that would be probably more confusing.

rev-list-options现在包含在其 man page 中:

--since-as-filter=<date>

Show all commits more recent than a specific date.

This visits all commits in the range, rather than stopping at the first commit which is older than a specific date.

关于git - 如何使用 git log --since 产生可靠的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67590215/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com