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

一曲冷凌霜 提交于 2019-12-04 18:03:47

Note that Git 2.14.x/2.15 has fixed some issues with reflog.
See 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).
(Merged by Junio C Hamano -- gitster -- in commit 3ab01ac, 11 Aug 2017)

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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!