10

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

Léo Natan
  • 56,823
  • 9
  • 150
  • 195

4 Answers4

18

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.

poke
  • 369,085
  • 72
  • 557
  • 602
  • 2
    Great answer, better than mine :) but you probably need additional `--follow` to detect renames. – Patryk Obara Dec 07 '16 at 09:46
  • Thank you! How about number of lines changed? – Léo Natan Dec 07 '16 at 09:48
  • @LeoNatan That’s a different question, and a bit more complicated; you could parse the output from `git log --shortstat` similar to Patryk’s answer. But check out [this question](http://stackoverflow.com/questions/2787253/show-number-of-changed-lines-per-author-in-git) for more ideas. – poke Dec 07 '16 at 09:55
3

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
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
1
$ 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

:)

Patryk Obara
  • 1,847
  • 14
  • 19
1
git log --format="%cn" | sort | uniq -c | sort -nr

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

GilZ
  • 6,418
  • 5
  • 30
  • 40