如何正确使用 `git reflog --since=...`?

How to properly use `git reflog --since=...`?

我有一个存储库,其中常规 git reflog --date=iso 显示了很多条目,例如,请参阅此片段 https://gist.github.com/FreddieChopin/0206c9ef530a056c624b065eed048c9d

您可能已经注意到,有 2 月 19 日、22 日、23 日、24 日、25 日和 26 日的刷新。

但是如果我想将输出限制为特定日期,这将无法按预期工作。例如 git reflog --date=iso --since="2017-02-20" 只给出这个 https://gist.github.com/FreddieChopin/fb7619dee8fde055a1cce6f6ff2f6eb6 - 它停止在“52896f49 HEAD@{2017-02-24 20:53:29 +0100}”,即使在那之前的 2 月 20 日以来有 reflog .甚至还有 24 日更短时间的 reflog,所以我不知道为什么它就停在那里。

我检查过的另一个存储库也有同样的问题,所以这似乎与 reflog 本身有关,而不是特定的存储库。另一个回购协议的问题甚至更奇怪,例如 git reflog --since="50.weeks" 给出了我最近几天 的提交,而 git reflog --since="60.weeks" 开始更早- 在那个回购协议中,自几年前以来也有定期提交。

另一方面,git log --since=... 完全按照预期工作,所以我不确定这里的问题是什么...

请注意 Git 2.14.x/2.15 已修复一些与 reflog 相关的问题。
参见 commit de23944, commit d08565b, commit 7f97de5, commit 7c2f08a, commit f35650d, commit 82fd0f4, commit 7cf686b (07 Jul 2017), and commit 822601e (09 Jul 2017) by Jeff King (peff)
(由 Junio C Hamano -- gitster -- in commit 3ab01ac 合并,2017 年 8 月 11 日)

reflog-walk: apply --since/--until to reflog dates

When doing a reflog walk, we use the commit's date to do any date limiting. In earlier versions of Git, this could lead to nonsense results, since a skipped commit would truncate the traversal.
So a sequence like:

git commit ...
git checkout week-old-branch
git checkout -
git log -g --since=1.day.ago

would stop at the week-old-branch, even though the "git commit" entry further back is still interesting.

As of the prior commit, which uses a parent-less traversal of the reflog, you get the whole reflog minus any commits whose dates do not match the specified options.
This is arguably useful, as you could scan the reflogs for commits that originated in a certain range.

But more likely a user doing a reflog walk wants to limit based on the reflog entries themselves.
You can simulate --until with:

git log -g @{1.day.ago}

but there's no way to ask Git to traverse only back to a certain date. E.g.:

# show me reflog entries from the past day
git log -g --since=1.day.ago

This patch teaches the revision machinery to prefer the reflog entry dates to the commit dates when doing a reflog walk.
Technically this is a change in behavior that affects plumbing, but the previous behavior was so buggy that it's unlikely anyone was relying on it.

一个new series of tests has been added for reflog-walk.