[关闭]
@buoge 2017-07-24T14:34:00.000000Z 字数 7521 阅读 1597

git 代码工作统计

程序构建


gitstats 更加详细的统计信息,最终方案使用 gitstats

http://www.cartosquare.com/2016/08/27/statistic-git-commits/
https://github.com/hoxu/gitstats
https://github.com/hoxu/gitstats/issues/55

  1. git clone git://github.com/hoxu/gitstats.git
  2. cd gitstats
  3. Clone gitstats repository
  4. Get homebrew, if you not already have
  5. Install gnuplot via homebrew brew install gnuplot
  6. Symlink your python 2.7 installation to "python2"
  7. sudo ln -s /usr/bin/python2.7 /usr/local/bin/python2
  8. make install in repository root (xcode and developer tools are required)
  9. gitstats ~/Desktop/zaozuo-web ~/Desktop/gitstats/

git_stats 和 gitstats 类似

安装

gem install git_stats
或者
sudo apt-get install ruby
sudo gem install git_stats

生成报告

git_stats generate
* 需要安装gnplot
brew install gnplot

git log 统计

$(git config user.name) 可以替换为具体的作者名称比如 buoge

  1. git log --shortstat --author="buoge".......后面都一样
  1. 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 }'

扫描 Log 单独统计每个人的增删行数加强版

  1. 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:

  1. buoge added lines: 27352, removed lines: 9642, total lines: 17710
  2. gaoyang added lines: 367, removed lines: 186, total lines: 181
  3. lizhongwen added lines: 366248, removed lines: 216114, total lines: 150134
  4. wangzhe added lines: 32, removed lines: 33, total lines: -1
  5. wuchuanbo added lines: 99010, removed lines: 79580, total lines: 19430
  6. yanghong added lines: 95696, removed lines: 143302, total lines: -47606
  7. zhouyinxue added lines: 6, removed lines: 3, total lines: 3
  8. 杨鸿 added lines: 95433, removed lines: 142103, total lines: -46670
  9. 高杨 added lines: 342, removed lines: 161, total lines: 181
  10. 邱文丽 added lines: 416, removed lines: 179, total lines: 237

扫描 Log 统计增删行数版

https://maoxian.de/2015/12/1357.html

  1. 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";}'
  1. 609270166,: 16 files changed, 263 insertions(+), 1199 deletions(-), -936 net
  2. Gao: 0 files changed, 12 insertions(+), 25 deletions(-), -13 net
  3. gaoyang,: 63 files changed, 342 insertions(+), 161 deletions(-), 181 net
  4. lizhongwen,: 18181 files changed, 366261 insertions(+), 216048 deletions(-), 150213 net
  5. lizhongwen,wuchuanbo,: 23 files changed, 157 insertions(+), 205 deletions(-), -48 net
  6. lizhongwen,yanghong,: 34 files changed, 176 insertions(+), 90 deletions(-), 86 net
  7. lizhongwen,zhouyinxue,: 3 files changed, 5 insertions(+), 101 deletions(-), -96 net
  8. naga,: 5 files changed, 395 insertions(+), 232 deletions(-), 163 net
  9. naga,wuchuanbo,: 6 files changed, 64 insertions(+), 20 deletions(-), 44 net
  10. qiuwenli,: 50 files changed, 416 insertions(+), 179 deletions(-), 237 net
  11. wangzhe,: 15 files changed, 32 insertions(+), 33 deletions(-), -1 net
  12. wuchuanbo,: 7611 files changed, 97807 insertions(+), 78776 deletions(-), 19031 net
  13. wuchuanbo,609270166,: 4 files changed, 14 insertions(+), 9 deletions(-), 5 net
  14. wuchuanbo,lizhongwen,: 30 files changed, 406 insertions(+), 110 deletions(-), 296 net
  15. wuchuanbo,yanghong,: 16 files changed, 189 insertions(+), 157 deletions(-), 32 net
  16. yanghong,: 6106 files changed, 94317 insertions(+), 141824 deletions(-), -47507 net
  17. yanghong,lizhongwen,: 68 files changed, 726 insertions(+), 156 deletions(-), 570 net
  18. yanghong,wuchuanbo,: 12 files changed, 174 insertions(+), 69 deletions(-), 105 net
  19. zhouyinxue,: 5 files changed, 6 insertions(+), 3 deletions(-), 3 net

git-fame-rb 使用这个工具可以直接输出非常漂亮的统计表格

https://github.com/oleander/git-fame-rb

  1. gem install git_fame
  1. 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"
  1. Total number of files: 2,053
  2. Total number of lines: 63,132
  3. Total number of commits: 4,330
  4. +------------------------+--------+---------+-------+--------------------+
  5. | name | loc | commits | files | percent |
  6. +------------------------+--------+---------+-------+--------------------+
  7. | Johan Sørensen | 22,272 | 1,814 | 414 | 35.3 / 41.9 / 20.2 |
  8. | Marius Mathiesen | 10,387 | 502 | 229 | 16.5 / 11.6 / 11.2 |
  9. | Jesper Josefsson | 9,689 | 519 | 191 | 15.3 / 12.0 / 9.3 |
  10. | Ole Martin Kristiansen | 6,632 | 24 | 60 | 10.5 / 0.6 / 2.9 |
  11. | Linus Oleander | 5,769 | 705 | 277 | 9.1 / 16.3 / 13.5 |
  12. | Fabio Akita | 2,122 | 24 | 60 | 3.4 / 0.6 / 2.9 |
  13. | August Lilleaas | 1,572 | 123 | 63 | 2.5 / 2.8 / 3.1 |
  14. | David A. Cuadrado | 731 | 111 | 35 | 1.2 / 2.6 / 1.7 |
  15. | Jonas Ängeslevä | 705 | 148 | 51 | 1.1 / 3.4 / 2.5 |
  16. | Diego Algorta | 650 | 6 | 5 | 1.0 / 0.1 / 0.2 |
  17. | Arash Rouhani | 629 | 95 | 31 | 1.0 / 2.2 / 1.5 |
  18. | Sofia Larsson | 595 | 70 | 77 | 0.9 / 1.6 / 3.8 |
  19. | Tor Arne Vestbø | 527 | 51 | 97 | 0.8 / 1.2 / 4.7 |
  20. | spontus | 339 | 18 | 42 | 0.5 / 0.4 / 2.0 |
  21. | Pontus | 225 | 49 | 34 | 0.4 / 1.1 / 1.7 |
  22. +------------------------+--------+---------+-------+--------------------+

使用 cloc 统计你的代码量,统计总量并非个人代码提交

代码提交统计,cloc 也支持使用 --diff 选项对两个版本的代码量进行比较。
https://echohn.github.io/2016/09/24/use-cloc-to-count-your-code/

  1. npm install -g cloc # https://www.npmjs.com/package/cloc
  2. sudo apt-get install cloc # Debian, Ubuntu
  3. sudo yum install cloc # Red Hat, Fedora
  4. sudo dnf install cloc # Fedora 22 or later
  5. sudo pacman -S cloc # Arch
  6. sudo pkg install cloc # FreeBSD
  7. sudo port install cloc # Mac OS X with MacPorts
  8. brew install cloc # Mac OS X with Homebrew
  9. choco install cloc # Windows with Chocolatey
  1. You can use this shell script to count the number of lines in a remote Git repository with one command:
  2. #!/usr/bin/env bash
  3. git clone --depth 1 "$1" temp-linecount-repo &&
  4. printf "('temp-linecount-repo' will be deleted automatically)\n\n\n" &&
  5. cloc temp-linecount-repo &&
  6. rm -rf temp-linecount-repo
  7. Installation
  8. 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.
  9. 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.
  10. Usage
  11. 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”.
  12. Example output:
  13. $ cloc-git https://github.com/evalEmpire/perl5i.git
  14. Cloning into 'temp-linecount-repo'...
  15. remote: Counting objects: 200, done.
  16. remote: Compressing objects: 100% (182/182), done.
  17. remote: Total 200 (delta 13), reused 158 (delta 9), pack-reused 0
  18. Receiving objects: 100% (200/200), 296.52 KiB | 110.00 KiB/s, done.
  19. Resolving deltas: 100% (13/13), done.
  20. Checking connectivity... done.
  21. ('temp-linecount-repo' will be deleted automatically)
  22. 171 text files.
  23. 166 unique files.
  24. 17 files ignored.
  25. http://cloc.sourceforge.net v 1.62 T=1.13 s (134.1 files/s, 9764.6 lines/s)
  26. -------------------------------------------------------------------------------
  27. Language files blank comment code
  28. -------------------------------------------------------------------------------
  29. Perl 149 2795 1425 6382
  30. JSON 1 0 0 270
  31. YAML 2 0 0 198
  32. -------------------------------------------------------------------------------
  33. SUM: 152 2795 1425 6850
  34. -------------------------------------------------------------------------------
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注