Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get git to show commits in a specified date range for author date?

Tags:

git

git-show

Apparently this:

git log --all --after="<date> 00:00" --before="<date> 23:59" --author="<author>" 

filters commits based on the committer date. How can I make it show commits for a specified author date range ?

like image 397
Mr_and_Mrs_D Avatar asked May 18 '16 23:05

Mr_and_Mrs_D


People also ask

How do you see commits by author?

2 Answers. Show activity on this post. git log --author=<pattern> will show the commit log filtered for a particular author. ( --committer can be used for committer if the distinction is necessary).


2 Answers

Maybe I'm missing something, but wouldn't this be enough?

git log --pretty=format:"%ad - %an: %s" --after="2016-01-31" --until="2017-03-10" --author="John Doe" 

See also here

like image 162
jackdbd Avatar answered Sep 18 '22 06:09

jackdbd


You can't—at least, not in Git alone. (Reminder to others visiting this question: it's not about viewing the author date, it's about selecting commits by the author date, a la --since/--after and --until/--before. These selectors use the committer date, 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.)

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).

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 both flags has the same effect as --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 awk for more.

like image 39
torek Avatar answered Sep 20 '22 06:09

torek