git 如何让git在作者日期的指定日期范围内显示提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37311494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get git to show commits in a specified date range for author date?
提问by Mr_and_Mrs_D
采纳答案by torek
You can't—at least, not in Git alone. (Reminder to others visiting this question: it's not about viewingthe author date, it's about selecting commits bythe author date, a la --since
/--after
and --until
/--before
. These selectors use the committerdate, not the author date. Consider as an extreme example a commit made "now", so that its committer date is in the 2000s, but backdated in the author-date field to some day in the year 1999. If your selection range is "any time near the turn of the century" you'll de-select this commit, since its committer date is "now", more than a decade beyond 1999.)
你不能——至少,不能单独在 Git 中。(提醒访问此问题的其他人:这不是关于查看作者日期,而是关于按作者日期,la --since
/--after
和--until
/选择提交--before
。这些选择器使用提交者日期,而不是作者日期。考虑作为一个极端示例提交制作“现在”,以便其提交者日期在 2000 年代,但在作者日期字段中回溯到 1999 年的某一天。如果您的选择范围是“接近世纪之交的任何时间”,您将取消- 选择这个提交,因为它的提交日期是“现在”,比 1999 年晚了十多年。)
I consider this a small bug in Git: you should be able to request that it use the author date field anywhere you can request that it use the committer date field. This is easy with log formatting, since we have %ad
and %cd
and the like, but impossible with commit selection. The closest we have is that git rev-list
can sort by author-date (within general topo-sorting).
我认为这是 Git 中的一个小错误:您应该能够在任何可以请求它使用提交者日期字段的地方请求它使用作者日期字段。这对于日志格式化很容易,因为我们有%ad
等等%cd
,但对于提交选择则不可能。我们拥有的最接近的是git rev-list
可以按作者日期排序(在一般拓扑排序中)。
A global switch in git rev-list
, like --use-author-date
, would work as a simple patch, and would not be too hard to add to Git, but I think it would be better to have --min-author-age
and --max-author-age
or similar, and a "sort by author date" flag (independent of the general --topo-order
flag, so that setting bothflags has the same effect as --author-date-order
).
全局切换git rev-list
,例如--use-author-date
,将作为一个简单的补丁工作,并且不会太难添加到 Git,但我认为最好有--min-author-age
和--max-author-age
或类似的,以及“按作者日期排序”标志(独立于通用--topo-order
标志,因此设置两个标志具有与 ) 相同的效果--author-date-order
。
As a workaround, you can list all potentially-interesting commits (with git rev-list
or equivalent, such as git log
: use whatever specifier makes commits potentially interesting, except for date filters: in this case that's just --all
) and extract all of their author-date fields (with git log --format=%at
or whatever), then do your own pruning of the list of commit IDs, then re-submit the remaining commit IDs to git log --no-walk
. But this is painful at best. See Tim Beigeleisen's answer using awkfor more.
作为一种解决方法,您可以列出所有可能有趣的提交(带有git rev-list
或等效的,例如git log
:使用任何使提交可能有趣的说明符,日期过滤器除外:在这种情况下,只是--all
)并提取所有作者日期字段(带有git log --format=%at
或其他),然后自己修剪提交 ID 列表,然后将剩余的提交 ID 重新提交到git log --no-walk
. 但这充其量是痛苦的。有关更多信息,请参阅Tim Beigeleisen 使用 awk 的回答。
回答by Hymandbd
回答by Tim Biegeleisen
You can.
你可以。
But as @torek mentioned, you might not be able to do this with pure Git. One option would be to pipe some pretty format output from git log
into awk
, and check the author date there:
但正如@torek 所提到的,您可能无法使用纯 Git 执行此操作。一种选择是将一些漂亮的格式输出从git log
into管道中awk
,并在那里检查作者日期:
git log --date=iso --pretty=format:'%ad%x08%aN' | awk '##代码## >= "2013-01-01" && ##代码## <= "2013-12-01"'
Here, the %ad
gives the author date in ISO format, and %aN
gives the author name.
在这里,%ad
给出了 ISO 格式的作者日期,并%aN
给出了作者姓名。