Search This Blog

Thursday, November 26, 2020

Getting top contributors of given directory based on commit counts

git log --pretty=format:"%an%x09" dir | sort | uniq -c | sort -nr

git log --pretty option prints the contents of the commit logs in a given format (%an%x09b) for given directory, here %an is placeholder for Author Name and %x09 is placeholder for tab.

Output of first command will be series of author names of commits affecting given directory ordered by date.

Since we are not concerned with order we will just sort the output so that we can easily group the names using uniq -c which along with unique values prints the count.

Now the output is in alphabetical order of Author Names if we want to order by count of commits we can pipe it to sort -nr  where n represents sort by numerical value and r represents sort in reverse order.