Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git count lines by author
#!/bin/sh
git log --shortstat | grep -E "(Author: )(\b\s*([A-Z]\w+)){2}|fil(e|es) changed" | awk '
{
if($1 ~ /Author/) {
author = $2" "$3
} else {
files[author]+=$1
inserted[author]+=$4
deleted[author]+=$6
}
}
END { for (key in files) { print "Author: " key "\n\tfiles changed: ", files[key], "\n\tlines inserted: ", inserted[key], "\n\tlines deleted: ", deleted[key] } }
'
@Y130311-NAV

This comment has been minimized.

Copy link

Y130311-NAV commented Aug 6, 2019

When I tried this script on a git repository, at least one Author was missing in the otherwise very nice result.

@FlorianGuhl

This comment has been minimized.

Copy link

FlorianGuhl commented Aug 19, 2019

Yes, for us also many authors were missing, also Lines of Code are not shown with that script.

@schobner

This comment has been minimized.

Copy link

schobner commented Sep 4, 2019

This script count also the merge commits. That's obvious, but unfortunately, it looks like someone's commit a lot, who doesn't. How can i filter by commit name?
--no-merges Doesn't seem to be working.

@gianpaolof

This comment has been minimized.

Copy link

gianpaolof commented Oct 31, 2019

hello. That's very nice.
I think it needs a minor correction to handle lowercase names:

git log --shortstat | grep -E "(Author: )(\b\s*([a-zA-Z]\w+)){1,2}|fil(e|es) changed" | awk ' {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.