Skip to content

Instantly share code, notes, and snippets.

@dameninngenn
Created August 16, 2011 10:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dameninngenn/1148840 to your computer and use it in GitHub Desktop.
Save dameninngenn/1148840 to your computer and use it in GitHub Desktop.
git log sum example
% git log --stat --author=dameninngenn --since="2011-07-15" --before="2011-08-15" --no-merges | grep 'files changed' | awk '{ins += $4}{del += $6} END{print "total: "ins"insertions(+) "del"deletions(-)"}'
> total: 3385insertions(+) 1089deletions(-)
@Zemke
Copy link

Zemke commented Jan 14, 2021

Great command except when there are commits with only deletions, then the parameter order is messed up and deletions count for insertions.

% echo "4 files changed, 202 deletions(-)" | awk '{ins += $4}{del += $6} END{print "total: "ins"insertions(+) "del"deletions(-)"}'
total: 202insertions(+) 0deletions(-)

I use sed to add , 0 insertions(+) when necessary and then the parameter order for awk is restored.

% echo " 4 files changed, 202 deletions(-)" | sed -E 's/d, ([[:digit:]]+)/d, 0 insertions(+), \1/g'      
 4 files changed, 0 insertions(+), 202 deletions(-)                                                                             

TL;DR: The fixed command would be:

% git log --stat --author=dameninngenn --since="2011-07-15" --before="2011-08-15" --no-merges | grep 'files changed' | sed -E 's/d, ([[:digit:]]+)/d, 0 insertions(+), \1/g' | awk '{ins += $4}{del += $6} END{print "total: "ins"insertions(+) "del"deletions(-)"}'

@Zemke
Copy link

Zemke commented Jan 14, 2021

Bonus:

per authors in all branches

git log --all --since="11 days ago" --no-merges --pretty=format:%an | sort | uniq | xargs -I% -L1 bash -c 'echo $0; git log --all --stat --author="$0" --since="11 days ago" --no-merges | grep "files changed" | sed -E "s/d, ([[:digit:]]+) d/d, 0 insertions(+), \1 d/g" | awk '\''{ins += $4}{del += $6} END{print "total: "ins"insertions(+) "del"deletions(-)"}'\'';' "%"

Example output:

  Tobi Myers
  total: 409insertions(+) 76deletions(-)
  Rangid Kouthrapalli
  total: 1047insertions(+) 1165deletions(-)
  Roger Seifert
  total: 1013insertions(+) 2058deletions(-)
  Vanessa Lambert
  total: 71insertions(+) 34deletions(-)

@dameninngenn
Copy link
Author

Thank you for your opinion.
It seems great! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment