【问题标题】:How to properly use `git reflog --since=...`?如何正确使用`git reflog --since=...`?
【发布时间】:2017-07-17 20:30:09
【问题描述】:

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

您可能会注意到,2 月 19 日、22 日、23 日、24 日、25 日和 26 日会有 reflog。

但是,如果我想将输出限制在某些日期,这将无法按预期工作。例如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 日有 reflogs。甚至还有 24 日的 reflogs 时间更短,所以我不知道为什么它会停在那里。

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

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

【问题讨论】:

  • 确实,看起来像 git reflog 中的一个错误(我能够在我的一个存储库中重现类似的东西)。
  • git reflog 实际上只是伪装的git log --walk-reflogs(至少在这种情况下),--walk-reflogs 不能与许多其他git log 选项配合得很好。
  • @torek - 仅作记录 - 当我直接使用 git log -g / git log --walk-reflogs 时观察到相同的行为。
  • 对,我的意思是错误实际上在git log 中。它至少应该注意到--since 在这里不起作用。

标签: git git-reflog


【解决方案1】:

请注意,Git 2.14.x/2.15 已修复 reflog 的一些问题。
请参阅commit de23944commit d08565bcommit 7f97de5commit 7c2f08acommit f35650dcommit 82fd0f4commit 7cf686b(2017 年 7 月 7 日)和commit 822601e(2017 年 7 月 9 日)@9876542。 >(2017 年 8 月 11 日由 Junio C Hamano -- gitster -- 合并于 commit 3ab01ac

reflog-walk: 应用 --since/--until 到 reflog 日期

在进行 reflog walk 时,我们使用提交的日期来进行任何日期限制。在早期版本的 Git 中,这可能会导致无意义的结果,因为跳过的提交会截断遍历。
所以一个像这样的序列:

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

将停在前一周的分支,即使后面的“git commit”条目仍然很有趣。

从使用 reflog 的无父遍历的先前提交开始,您将获得整个 reflog 减去日期与指定选项不匹配的任何提交。
这可以说是有用的,因为您可以扫描 reflogs 以查找提交 起源于某个范围。

但更有可能进行 reflog walk 的用户希望根据 reflog 条目本身进行限制。
你可以模拟--until

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

但是没有办法让 Git 只遍历到 某个日期。例如:

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

这个补丁教会了修订机制更喜欢 进行 reflog 时,reflog 条目日期到提交日期 走路。
从技术上讲,这是一种影响行为的变化 管道,但以前的行为是如此错误,以至于 不太可能有人依赖它。

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

【讨论】:

    猜你喜欢
    • 2020-08-16
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 2016-07-26
    • 2011-02-06
    • 2012-04-18
    相关资源
    最近更新 更多