@buoge
2017-07-24T14:34:00.000000Z
字数 7521
阅读 1603
程序构建
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.git
cd gitstats
Clone gitstats repository
Get homebrew, if you not already have
Install gnuplot via homebrew brew install gnuplot
Symlink your python 2.7 installation to "python2"
sudo ln -s /usr/bin/python2.7 /usr/local/bin/python2
make 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: 17710
gaoyang added lines: 367, removed lines: 186, total lines: 181
lizhongwen added lines: 366248, removed lines: 216114, total lines: 150134
wangzhe added lines: 32, removed lines: 33, total lines: -1
wuchuanbo added lines: 99010, removed lines: 79580, total lines: 19430
yanghong added lines: 95696, removed lines: 143302, total lines: -47606
zhouyinxue 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 net
Gao: 0 files changed, 12 insertions(+), 25 deletions(-), -13 net
gaoyang,: 63 files changed, 342 insertions(+), 161 deletions(-), 181 net
lizhongwen,: 18181 files changed, 366261 insertions(+), 216048 deletions(-), 150213 net
lizhongwen,wuchuanbo,: 23 files changed, 157 insertions(+), 205 deletions(-), -48 net
lizhongwen,yanghong,: 34 files changed, 176 insertions(+), 90 deletions(-), 86 net
lizhongwen,zhouyinxue,: 3 files changed, 5 insertions(+), 101 deletions(-), -96 net
naga,: 5 files changed, 395 insertions(+), 232 deletions(-), 163 net
naga,wuchuanbo,: 6 files changed, 64 insertions(+), 20 deletions(-), 44 net
qiuwenli,: 50 files changed, 416 insertions(+), 179 deletions(-), 237 net
wangzhe,: 15 files changed, 32 insertions(+), 33 deletions(-), -1 net
wuchuanbo,: 7611 files changed, 97807 insertions(+), 78776 deletions(-), 19031 net
wuchuanbo,609270166,: 4 files changed, 14 insertions(+), 9 deletions(-), 5 net
wuchuanbo,lizhongwen,: 30 files changed, 406 insertions(+), 110 deletions(-), 296 net
wuchuanbo,yanghong,: 16 files changed, 189 insertions(+), 157 deletions(-), 32 net
yanghong,: 6106 files changed, 94317 insertions(+), 141824 deletions(-), -47507 net
yanghong,lizhongwen,: 68 files changed, 726 insertions(+), 156 deletions(-), 570 net
yanghong,wuchuanbo,: 12 files changed, 174 insertions(+), 69 deletions(-), 105 net
zhouyinxue,: 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,053
Total number of lines: 63,132
Total 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/cloc
sudo apt-get install cloc # Debian, Ubuntu
sudo yum install cloc # Red Hat, Fedora
sudo dnf install cloc # Fedora 22 or later
sudo pacman -S cloc # Arch
sudo pkg install cloc # FreeBSD
sudo port install cloc # Mac OS X with MacPorts
brew install cloc # Mac OS X with Homebrew
choco 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 bash
git 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-repo
Installation
This 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.
Usage
The 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.git
Cloning 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 0
Receiving 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 6382
JSON 1 0 0 270
YAML 2 0 0 198
-------------------------------------------------------------------------------
SUM: 152 2795 1425 6850
-------------------------------------------------------------------------------