Reputation: 177
I want to ask if there is a command in git that can list all authors names with the last date of their commit
(for example , author mike last commit was on feb, 2, 2017)
Im using git on mac iOS terminal and I'm a beginner in using git
thanks
Upvotes: 4
Views: 1610
Reputation: 60295
git log --pretty=%an%x09%ad | awk -F$'\t' '!seen[$1]++'
%x09
is character code 9, i.e. '\t'
. -F$'\t'
sets that as awk's field separator, seen[$1]++
is zero only the first time.
%an
prints the author's name, and %ad
prints the date of authorship.
Upvotes: 7
Reputation: 2826
This should get you pretty close. Save it and make it executable (chmod +x filename). Then, of course, execute it in your git project directory (./filename).
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for a in `git log --pretty="%an" | sort | uniq`; do git log --author="$a" --pretty="Author: %an Last commit: %ai" | head -n1; done
IFS=$SAVEIFS
I guess I should explain the strategy a bit. Essentially, we query git for all authors, then sort that list and winnow it down to unique entries:
`git log --pretty="%an" | sort | uniq`
Then for each of those unique authors, we do a git log for just that author and take only the top result, formatting it to our liking with --pretty:
git log --author="$a" --pretty="Author: %an Last commit: %ai" | head -n1
The rest is just the looping mechanism (bash's for loop). It didn't exactly work flawlessly for me, but reasonably close. Should be a good place to start tailoring it to your specific needs--enjoy!
NOTE: Added a couple of lines to the script related to IFS/SAVEIFS. This will fix the for loop breaking on author names with spaces in them, which is quite usual. Sorry to have missed that detail earlier.
Upvotes: 3
Reputation: 11060
The easiest option is to use the pretty
format options to git to achieve this kind of thing.
In this case, you probably want something like:
git log --pretty="%aD %an %ae"
git log
will output in reverse chronological order by default, so the first occurrence of a name is their last commit. So on *nix systems, something like the following will get the line you want:
git log --pretty="Author: %an last commit: %ai" |grep "mike" |head -n1
Look at man git-log
and the PRETTY FORMAT
section for all the %
macro options.
Upvotes: 2