Git 日志:按提交的作者日期过滤
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13987273/
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
Git log: filter by commit's author date
提问by atiking
I have such a commit
我有这样的承诺
commit 8a183536da1641afa6bd5a27ae391b387b7cd052
Author: hidden
AuthorDate: Fri Sep 7 10:13:59 2012
Commit: hidden
CommitDate: Fri Dec 7 17:29:24 2012
I want to filter the log and show the commit by AuthorDate.
我想过滤日志并按AuthorDate显示提交。
I tried --since
& --until
options, but it actually filter the CommitDate.
我尝试过--since
&--until
选项,但它实际上过滤了CommitDate。
That means I can only get the commit by
这意味着我只能通过
git log --since='2012-12-01' --until='2012-12-10'
If I want to get the commit filter by start_date '2012-09-01' and end_date '2012-09-10'
如果我想通过 start_date '2012-09-01' 和 end_date '2012-09-10' 获取提交过滤器
Any tips?
有小费吗?
回答by 1berto
git log --format=format:"%ai %aE %s"
and then grep by AuthorName and/or date!
然后按作者姓名和/或日期 grep!
回答by skalee
I'm afraid you need to do some scripting:
恐怕您需要编写一些脚本:
git log --format="%ad %H" --date=iso | sort | ruby -ane 'date = $F[0] ; hash = $F[3] ; puts hash if ("2013-08-23".."2013-09-26").cover?(date)'
gave to me:
给了我:
3eddb854eaea971e9a60147153f0f3c9be4f1a5a dfeefd4715c4fddef0957c5aff238c525bb1def6 db654badb97f3784286171d4645e9face6a42865 62cdba07e6ae0cd28752491a83f584d3e18a5619 7643a0458a54200f8944583d66c089d63c1bf688 23b720852a36e959d0f45f9d11f05d4aa7ee0cb9 f729ec9c5bf37ee0284a8db47cbc79a0b53145bb bc2d647ae86fbff1246ba163a5a99d25ed2f3523 a0752b3cbae39698449be953153ddaafe35c054c 8e88fffc75cbdda333c86cb4f5eb9b5b30263c27
Unfortunately, git log 3eddb854eaea971e9a60147153f0f3c9be4f1a5a..8e88fffc75cbdda333c86cb4f5eb9b5b30263c27
is not guaranteed to work because those commits may be in different branches.
不幸的是,git log 3eddb854eaea971e9a60147153f0f3c9be4f1a5a..8e88fffc75cbdda333c86cb4f5eb9b5b30263c27
不能保证工作,因为这些提交可能在不同的分支中。
Let's explain what I did:
让我们解释一下我做了什么:
--format="%ad %H"
– format log asauthor_date commit_hash
lines--date=iso
– dates inYY-mm-dd HH:MM:SS
formatsort
– Unix command which sorts lines alphabetically; it's suitable to sort dates in ISO formatruby -ane
– execute ruby script. -n means execute for every line, -a split those lines and put fields into$F
array, -e precises script to execute("2011-02-23".."2011-02-26").cover?(date)
– create range from two strings and check if date fits it inclusively (in the meaning of alphabetical order, we were not parsing those dates)
--format="%ad %H"
– 将日志格式化为author_date commit_hash
行--date=iso
– 日期YY-mm-dd HH:MM:SS
格式sort
– 按字母顺序排列行的 Unix 命令;适合对 ISO 格式的日期进行排序ruby -ane
– 执行 ruby 脚本。-n 表示对每一行执行,-a 拆分这些行并将字段放入$F
数组,-e 精确执行要执行的脚本("2011-02-23".."2011-02-26").cover?(date)
– 从两个字符串创建范围并检查日期是否包含在内(按照字母顺序的含义,我们没有解析这些日期)
I have no idea what to do next (to give you nicer log), but glad to move you to this point.
我不知道下一步该做什么(为您提供更好的日志),但很高兴让您走到这一步。
回答by jpo
I sometimes want to know the commits autored by me on a certain date. For that I use git log --all --author=jpo --format="%ai %s" |grep -E ^2015-09-01
. Unfortunately that approach wont work for filtering by date range in general but for the range used in the question it could be easily done: git log --all --author=jpo --format="%ai %s" |grep -E ^2012-12-(0.|10)
If you want more information about the commits besides author date and commit message just add more parameters to the format string (check the PRETTY FORMATS section of the git help log
page).
有时我想知道我在某个日期自动提交的提交。为此,我使用git log --all --author=jpo --format="%ai %s" |grep -E ^2015-09-01
. 不幸的是,这种方法通常不适用于按日期范围过滤,但对于问题中使用的范围,它可以很容易地完成:git log --all --author=jpo --format="%ai %s" |grep -E ^2012-12-(0.|10)
如果您想要更多关于除了作者日期和提交消息之外的提交的信息,只需向格式字符串添加更多参数(检查页面的漂亮格式部分git help log
)。