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

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 ?


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


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.


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:

git log --date=iso --pretty=format:'%ad%x08%aN' | awk '$0 >= "2013-01-01" && $0 <= "2013-12-01"'

Here, the %ad gives the author date in ISO format, and %aN gives the author name.


inspired by Tim Biegeleisen's answer above.

git log --all --date=iso --pretty=format:'%ad%x08%aN %s' | grep 2020-06-09 | sort -u

did what I needed. I want author's date, not commits date because I rebase and squash a lot. but I keep important dates on import commits.

related to that, I have a small helper allowing me to reset the author's email but keeping the original author's date. --reset-author by default overwrites the author's date.

https://github.com/mathieujobin/git-scripts/blob/master/bin/git-reset-author-but-not-date

on the git log above, when needed, you can add %H to get the gitsha