22. July 2021 3 min read
List all authors of git commits on branch in last 30 days
I wanted to have a bit of an overview about what is going on with my branch in the last 30 days. It was hijacked by some co-developers and in the end I wanted to see who contributed the most. But the problem was that while GitHub and GitLab do provide some statistics, they are for a master or main branch and they cannot be filtered by time. So my specific request was to see who contributed to my branch in the last 30 days.
Git get all commits from last 30 days
Getting commits from the last 30 days is actually quite simple and it is a general git log command, but here I included some more styling to make it easier to parse.
git log --format='%aN <%aE>' --since=30.days
Filtering out only authors using awk
Always when there is a multi-line text output I need to parse I jump to awk and its capabilities. So here is a solution that uses < as a separator and counts the number of authors that repeat. The output here is basically number of commits and author name.
awk '{FS="<"} ; {arr[$1]++} END{for (i in arr){print arr[i], i;}}'
Combine it all together in bash one-liner and use sort to get order
Now for the final solution we simply run above command consequently and use sort to get the sorted output. So the final solution that will print out the list of authors with number of commits on your current branch is:
git log --format='%aN <%aE>' --since=30.days | awk '{FS="<"} ; {arr[$1]++} END{for (i in arr){print arr[i], i;}}' | sort -rn
Hope it helped you with your problem, but if you have a better solution then just comment below.