如何正确使用`git reflog --since = ...`? [英] How to properly use `git reflog --since=...`?

查看:111
本文介绍了如何正确使用`git reflog --since = ...`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



您可能会注意到,二月十九号,二十二号,二十三号,二十四号,二十四号,二十五号和二十六号都有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日之前还有reflog。甚至有24小时reflogs,所以我不知道为什么它停止在那里。



同样的问题是我检查了另一个存储库,所以这似乎与reflog本身相关,而不是特定的存储库。其他仓库的问题甚至是更加诡异,例如 git reflog --since =50.weeks给出了我最近几个天的提交 strong>,而 git reflog --since =60.weeks开始进一步回溯 - 因为回购数据库还有几年前的常规提交。另一方面, git log --since = ... 完全按预期工作,所以我' m不知道这里有什么问题...

解决方案

请注意,Git 2.14.x / 2.15修复了reflog的一些问题。

请参阅 commit de23944 commit d08565b 提交7f97de5 commit 7c2f08a 提交f35650d commit 7cf686b (2017年7月7日)和 commit 822601e (2017年7月9日)由 Jeff King( peff

(由 Junio C Hamano - gitster -


reflog-walk:apply --since / - 直到reflog日期



在执行reflog日志时,我们使用commit的日期来执行任何日期限制。在早期版本的Git中,这可能会导致无意义的结果,因为跳过的提交会截断遍历。

因此,一个序列就像:



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




会停留在week-old-分支,即使 git commit 条目的后面仍然有趣。



使用reflog的无亲本遍历,您会得到整个reflog减去任何提交的日期与指定选项不匹配的提交。

这可以说是有用的,因为您可以扫描提交$ b的reflog $ b $起源于一定的范围。

但是更可能的是,用户进行reflog步行时想根据reflog条目本身进行限制。




 <$ c可以模拟  - 直到 $ CG it log -g @ {1.day.ago} 




没办法让Git只能回溯到
某个日期。例如:



 #显示过去一天的reflog条目
git log - g --since = 1.day.ago




这个补丁教导修改机制以便在执行reflog
walk时将
reflog输入日期更改为提交日期。

从技术上讲,这是影响
管道的行为变化,但是以前的行为太麻烦了,它是
不太可能有人依赖它。


A reflog-walk


I have a repository for which a regular git reflog --date=iso shows a lot of entries, for example see this fragment https://gist.github.com/FreddieChopin/0206c9ef530a056c624b065eed048c9d

As you may notice, there are reflogs for 19th, 22nd, 23rd, 24th, 25th and 26th of February.

But if I would like to limit the output to certain dates, this doesn't work as expected. For example git reflog --date=iso --since="2017-02-20" gives only this https://gist.github.com/FreddieChopin/fb7619dee8fde055a1cce6f6ff2f6eb6 - it stops at "52896f49 HEAD@{2017-02-24 20:53:29 +0100}", even though there are reflogs since 20th of February before that. There are even reflogs for 24th with smaller hours, so I have no idea why it stops exactly there.

The same problem is with another repository I've checked, so this seems to be related to the reflog itself, not the particular repository. The problem with the other repo is even weirder, as for example git reflog --since="50.weeks" gives my commits from the last several days, while git reflog --since="60.weeks" starts to go further back in time - in that repo there are also regular commits since a few years back.

On the other hand, git log --since=... works exactly as expected, so I'm not sure what's the problem here...

解决方案

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.

这篇关于如何正确使用`git reflog --since = ...`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆