Finding the most frequent committer to a specific

2020-06-03 10:04发布

问题:

Given a specific file in a git repository, how would I go about finding who are the most frequent committers in that file?

回答1:

You can use git shortlog for this:

git shortlog -sn -- path/to/file

This will print out a list of authors for the path, ordered and prefixed by the commit count.

Usually, this command is used to get a quick summary of changes, e.g. to generate a changelog. With -s, the change summaries are suppressed, leaving only the author names. And paired with -n, the output is sorted by the the commit count.

Of course, instead of the path to a file, you can also use a path to a directory to look at the commits to that path instead. And if you leave off the path completely, git shortlog -sn gives you statistics for the whole repository.



回答2:

You can short output according to the number of commits per user.

$ git shortlog -sen <file/path>

Here,
-s for commit summary
-e for email
-n short by number instead of alphabetic order  

// more info
$ git shortlog --help


回答3:

$ git log --follow <file> | grep "Author: " | sort | uniq -c | sort

Some explanation:

git log --follow <file> - limit log to specific file, follow through all renames of this file

grep "Author:" | sort - take only lines with Authors and group authors together

uniq -c | sort - count authors in groups and sort it again, so most frequent one is in first line

:)



回答4:

git log --format="%cn" | sort | uniq -c | sort -nr

Get the committer name of each commit, group and count, sort in descending order.



标签: git