How can I get the Git commits done in the last 3 months counted from the last commit on a branch?

Viewed 233

I know that e.g. with

git shortlog -sn --since=3.months <branch>

I can get the commits done in the last 3 months on <branch> counted from now. But how can I make the 3.months count from the date of the last commit on <branch> instead? Is there a syntax for this to work in a single command, or would it require multiple git invocations?

1 Answers

Get the date of the last commit on the branch with git log --format='%ai' <branch> -n1. date can do date math, so use that to subtract 3 months. Then feed that to --since.

git log --since "$(date --date "$(git log --format='%ai' <branch> -n1) - 3 months")" <branch>

You will probably want to turn this into an alias.

Related