oskbor oskbor - 1 year ago 91
Git Question

Search git history and group by author

Let say I want to count how many

statements have been commited and then group them by author, how would I do that?

Example of what I want to do:

git count-by-author "if ("

245 Author A
199 Author B
20 Author C

I'm mainly interested in number of
s introduced, and not modified
statements, if that is possible.

qzb qzb
Answer Source

There is no pure git solution, but you can use following bash script to get such stats:

for sha in $(git log --format=%H); do
  author="$(git show --format=%an $sha | head -n1)"

  removed_if_statements=$(git show $sha | grep -E '^\-(.* )?if \(' | wc -l)
  added_if_statements=$(git show $sha | grep -E '^\+(.* )?if \(' | wc -l)

  delta=$(( $added_if_statements - $removed_if_statements ))

  if [ $delta -gt 0 ]; then
    for x in {1..$delta}; do
      echo $author
done | sort | uniq -c | sort -rg
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download