Nick
Nick

Reputation: 9051

How to get last commit time of every user in a git repo?

There are many persons working on the same git repo. I'd like to list each person's last commit time. Like:

Alice Nov 22 
Bob Nov 21 
Charlie Nov 29

...

I know that I can get a specific person's last commit using:

git log --author="bob" -1

Is it possible to get everybody's last commit time?

Upvotes: 1

Views: 71

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 21978

(1) First, you can build the authors' list by sorting the log with

git log --all --pretty=format:"%aN" | sort -u

At this point, let's note that you might want to use a .mailmap to normalize your repo's possible multiple aliases for authors (or else Joe Schmoe will be considered a different author from joeshmoe and joe.schmoe.home, which are the other names of the same author but from different machines).

(2) Then just loop over the list with a while, and get the most recent commit for each one, like

git log --all --pretty=format:"%aN" | sort -u | while read -r line ; do git log --all --pretty="%aN %ad" --date=short -1 --author="$line"; done

...finally (3) since noone wants to have to type this long chain of commands each time, the almost mandatory alias could be

# set the alias
git config --global alias.autlog '!git log --all --pretty=format:"%aN" | sort -u | while read -r line ; do git log --all --pretty="%aN %ad" --date=short -1 --author="$line"; done'

# use it
git autlog

Upvotes: 1

Related Questions