Skip to content

Instantly share code, notes, and snippets.

@erizhang
Created September 18, 2019 09:01
Show Gist options
  • Save erizhang/546df48c5e8be4ba3ce57b32a9836b6f to your computer and use it in GitHub Desktop.
Save erizhang/546df48c5e8be4ba3ce57b32a9836b6f to your computer and use it in GitHub Desktop.
One awk script to format the output of git log to statistics the file change and LoC insertions/deletions
#git log --shortstat --since="1 Jan, 2019" > log.txt
BEGIN {
commit="";
date="";
file=0;
add=0;
del=0;
}
{
if (index($1, "commit")!=0)
commit=$2;
if (index($1, "Date:")!=0)
date=sprintf("%s %s, %s", $3, $4, $6);
if (index($3, "changed")!=0){
file=$1;
if(index($0, "insertions")!=0 && index($0, "deletions")!=0){
add=$4;
del=-$6;
}
else {
if(index($0, "insertions")!=0)
add=$4;
else
del=-$4
}
printf("%s;%s;%s;%s;%s\n", commit,date,file,add,del);
file=0;
add=0;
del=0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment