Git 统计代码量

命令一:指定用户名和起止日期。

git log --since="2019-10-01" --before="2019-10-21" --author="username" 
--pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } 
END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'

命令二:当前用户最近的代码量.

git log --since="2019-10-01" --until=date --author="$author" 
--pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } 
END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'

制作成shell脚本:(countCodeLLine.sh)

#!/bin/bash

read -p "输入开始日期(如:2019-10-01)" startDate

if[-f count CodeRes.txt];then
    rm CodeRes.txt
fi

function countCode{
    countCoudeRes=`git log --since=${startDate} --until=date --author="$author" 
--pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } 
END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }`
    echo "${author} ${startDate} ~ `date` ${countCoudeRes}"
    echo "${author} ${startDate} ~ `date` ${countCoudeRes}" >> countCodeRes.txt

}

countCode


sleep 1

制作成bat脚本:(countCodeLLine.bat)

echo "windows .bat call .shell script"
"D:\development\Git\bin\sh.exe"  --login -i -c "./countCodeLLine.sh"

 

你可能感兴趣的:(git,工具使用)