Find all authors of a file in a git repository

Posted on 2015-04-06

Just a handy (but sort of dirty) script I wrote for a friend of mine, to find all the authors of a particular file in a git repository.

#!/bin/bash

# usage: git-find-authors <filename>

git blame -p $1 | grep ^"author " | cut -d' ' -f2- > /tmp/file1
git blame -p $1 | grep ^"author-mail" | cut -d' ' -f 2 > /tmp/file2
paste -d ' '  /tmp/file1 /tmp/file2 | sort | uniq

Another friend came up with a one-liner that is probably more accurate. We really don’t want to do git blame to find who changed line by line, in fact we could miss out some authors whose code got rewritten. So here it is, please don’t use the above one and use the below script instead.

git shortlog -s -e $1 | cut -f1 --complement