Home > Software design >  How to get last commit time of every user in a git repo?
How to get last commit time of every user in a git repo?

Time:12-01

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?

CodePudding user response:

(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            
  •  Tags:  
  • git
  • Related