Given a specific file in a git repository, how would I go about finding who are the most frequent committers in that file?
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.
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
$ 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
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With