@buoge
2017-07-24T06:34:00.000000Z
字数 7521
阅读 1936
程序构建
http://www.cartosquare.com/2016/08/27/statistic-git-commits/
https://github.com/hoxu/gitstats
https://github.com/hoxu/gitstats/issues/55
git clone git://github.com/hoxu/gitstats.gitcd gitstatsClone gitstats repositoryGet homebrew, if you not already haveInstall gnuplot via homebrew brew install gnuplotSymlink your python 2.7 installation to "python2"sudo ln -s /usr/bin/python2.7 /usr/local/bin/python2make install in repository root (xcode and developer tools are required)gitstats ~/Desktop/zaozuo-web ~/Desktop/gitstats/
gem install git_stats
或者
sudo apt-get install ruby
sudo gem install git_stats
git_stats generate
* 需要安装gnplot
brew install gnplot
$(git config user.name) 可以替换为具体的作者名称比如 buoge
git log --shortstat --author="buoge".......后面都一样
git log --shortstat --author="$(git config user.name)" | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6; delta+=$4-$6; ratio=deleted/inserted} END {printf "Commit stats:\n- Files changed (total).. %s\n- Lines added (total).... %s\n- Lines deleted (total).. %s\n- Total lines (delta).... %s\n- Add./Del. ratio (1:n).. 1 : %s\n", files, inserted, deleted, delta, ratio }'
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --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 }' -; done
result:
buoge added lines: 27352, removed lines: 9642, total lines: 17710gaoyang added lines: 367, removed lines: 186, total lines: 181lizhongwen added lines: 366248, removed lines: 216114, total lines: 150134wangzhe added lines: 32, removed lines: 33, total lines: -1wuchuanbo added lines: 99010, removed lines: 79580, total lines: 19430yanghong added lines: 95696, removed lines: 143302, total lines: -47606zhouyinxue added lines: 6, removed lines: 3, total lines: 3杨鸿 added lines: 95433, removed lines: 142103, total lines: -46670高杨 added lines: 342, removed lines: 161, total lines: 181邱文丽 added lines: 416, removed lines: 179, total lines: 237
git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'
609270166,: 16 files changed, 263 insertions(+), 1199 deletions(-), -936 netGao: 0 files changed, 12 insertions(+), 25 deletions(-), -13 netgaoyang,: 63 files changed, 342 insertions(+), 161 deletions(-), 181 netlizhongwen,: 18181 files changed, 366261 insertions(+), 216048 deletions(-), 150213 netlizhongwen,wuchuanbo,: 23 files changed, 157 insertions(+), 205 deletions(-), -48 netlizhongwen,yanghong,: 34 files changed, 176 insertions(+), 90 deletions(-), 86 netlizhongwen,zhouyinxue,: 3 files changed, 5 insertions(+), 101 deletions(-), -96 netnaga,: 5 files changed, 395 insertions(+), 232 deletions(-), 163 netnaga,wuchuanbo,: 6 files changed, 64 insertions(+), 20 deletions(-), 44 netqiuwenli,: 50 files changed, 416 insertions(+), 179 deletions(-), 237 netwangzhe,: 15 files changed, 32 insertions(+), 33 deletions(-), -1 netwuchuanbo,: 7611 files changed, 97807 insertions(+), 78776 deletions(-), 19031 netwuchuanbo,609270166,: 4 files changed, 14 insertions(+), 9 deletions(-), 5 netwuchuanbo,lizhongwen,: 30 files changed, 406 insertions(+), 110 deletions(-), 296 netwuchuanbo,yanghong,: 16 files changed, 189 insertions(+), 157 deletions(-), 32 netyanghong,: 6106 files changed, 94317 insertions(+), 141824 deletions(-), -47507 netyanghong,lizhongwen,: 68 files changed, 726 insertions(+), 156 deletions(-), 570 netyanghong,wuchuanbo,: 12 files changed, 174 insertions(+), 69 deletions(-), 105 netzhouyinxue,: 5 files changed, 6 insertions(+), 3 deletions(-), 3 net
https://github.com/oleander/git-fame-rb
gem install git_fame
git fame --by-type --include "zaozuo-ios/Classes/business/*.swift,zaozuo-ios/Classes/business/*.xib,zaozuo-ios/Classes/common/*.swift,zaozuo-ios/Classes/common/*.xib,zaozuo-ios/Classes/sdk/*.swift,zaozuo-ios/Classes/sdk/*.xib"
Total number of files: 2,053Total number of lines: 63,132Total number of commits: 4,330+------------------------+--------+---------+-------+--------------------+| name | loc | commits | files | percent |+------------------------+--------+---------+-------+--------------------+| Johan Sørensen | 22,272 | 1,814 | 414 | 35.3 / 41.9 / 20.2 || Marius Mathiesen | 10,387 | 502 | 229 | 16.5 / 11.6 / 11.2 || Jesper Josefsson | 9,689 | 519 | 191 | 15.3 / 12.0 / 9.3 || Ole Martin Kristiansen | 6,632 | 24 | 60 | 10.5 / 0.6 / 2.9 || Linus Oleander | 5,769 | 705 | 277 | 9.1 / 16.3 / 13.5 || Fabio Akita | 2,122 | 24 | 60 | 3.4 / 0.6 / 2.9 || August Lilleaas | 1,572 | 123 | 63 | 2.5 / 2.8 / 3.1 || David A. Cuadrado | 731 | 111 | 35 | 1.2 / 2.6 / 1.7 || Jonas Ängeslevä | 705 | 148 | 51 | 1.1 / 3.4 / 2.5 || Diego Algorta | 650 | 6 | 5 | 1.0 / 0.1 / 0.2 || Arash Rouhani | 629 | 95 | 31 | 1.0 / 2.2 / 1.5 || Sofia Larsson | 595 | 70 | 77 | 0.9 / 1.6 / 3.8 || Tor Arne Vestbø | 527 | 51 | 97 | 0.8 / 1.2 / 4.7 || spontus | 339 | 18 | 42 | 0.5 / 0.4 / 2.0 || Pontus | 225 | 49 | 34 | 0.4 / 1.1 / 1.7 |+------------------------+--------+---------+-------+--------------------+
代码提交统计,cloc 也支持使用 --diff 选项对两个版本的代码量进行比较。
https://echohn.github.io/2016/09/24/use-cloc-to-count-your-code/
npm install -g cloc # https://www.npmjs.com/package/clocsudo apt-get install cloc # Debian, Ubuntusudo yum install cloc # Red Hat, Fedorasudo dnf install cloc # Fedora 22 or latersudo pacman -S cloc # Archsudo pkg install cloc # FreeBSDsudo port install cloc # Mac OS X with MacPortsbrew install cloc # Mac OS X with Homebrewchoco install cloc # Windows with Chocolatey
它有诸多优点:
You can use this shell script to count the number of lines in a remote Git repository with one command:#!/usr/bin/env bashgit clone --depth 1 "$1" temp-linecount-repo &&printf "('temp-linecount-repo' will be deleted automatically)\n\n\n" &&cloc temp-linecount-repo &&rm -rf temp-linecount-repoInstallationThis script requires CLOC (“Count Lines of Code”) to be installed. cloc can probably be installed with your package manager – for example, brew install cloc with Homebrew.You can install the script by saving its code to a file cloc-git, running chmod +x cloc-git, and then moving the file to a folder in your $PATH such as /usr/local/bin.UsageThe script takes one argument, which is any URL that git clone will accept. Examples are https://github.com/evalEmpire/perl5i.git (HTTPS) or git@github.com:evalEmpire/perl5i.git (SSH). You can get this URL from any GitHub project page by clicking “Clone or download”.Example output:$ cloc-git https://github.com/evalEmpire/perl5i.gitCloning into 'temp-linecount-repo'...remote: Counting objects: 200, done.remote: Compressing objects: 100% (182/182), done.remote: Total 200 (delta 13), reused 158 (delta 9), pack-reused 0Receiving objects: 100% (200/200), 296.52 KiB | 110.00 KiB/s, done.Resolving deltas: 100% (13/13), done.Checking connectivity... done.('temp-linecount-repo' will be deleted automatically)171 text files.166 unique files.17 files ignored.http://cloc.sourceforge.net v 1.62 T=1.13 s (134.1 files/s, 9764.6 lines/s)-------------------------------------------------------------------------------Language files blank comment code-------------------------------------------------------------------------------Perl 149 2795 1425 6382JSON 1 0 0 270YAML 2 0 0 198-------------------------------------------------------------------------------SUM: 152 2795 1425 6850-------------------------------------------------------------------------------