Show Git Commits in a Date Range with --since and --until
List commits between two dates with git log --since and --until. Both use the commit date, and a date without a time takes its time of day from the clock.
You want the commits from a particular stretch, such as one month or one release cycle.
git init -q repo && cd repo
git config user.name Ann && git config user.email [email protected]
for d in 2024-02-03 2024-02-15 2024-02-29 2024-03-04; do
GIT_AUTHOR_DATE="${d}T12:00:00Z" GIT_COMMITTER_DATE="${d}T12:00:00Z" git commit -q --allow-empty -m "work on $d"
done
git log --since=2024-02-10 --until='2024-02-29 00:00' --format='%ad %s' --date=short
echo "---"
git log --since=2024-02-10 --until='2024-02-29 23:59:59' --format='%ad %s' --date=short2024-02-15 work on 2024-02-15
---
2024-02-29 work on 2024-02-29
2024-02-15 work on 2024-02-15--since and --until (also spelled --after and --before) keep the commits whose commit date falls inside the range. With --until='2024-02-29 00:00' the commit made at noon on the 29th is left out, and with 23:59:59 it is included, so the time you write decides what the last day contains. Git also accepts relative dates such as 2 weeks ago. See git log.
The dates are commit dates, not author dates, so a rebased or cherry-picked commit moves into the range of the day it was rewritten. Always give a time when the end of the range matters, because a bare date is filled in from the current time and the result depends on when you run it. Time zones come from the local setting unless you write one.