0
点赞
收藏
分享

微信扫一扫

项目代码行数统计

small_Sun 2022-08-29 阅读 146

一、git命令统计


1、统计某人代码提交量


git log --author="mengfanxiao" --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 }' -


2、统计所有人代码提交量(指定统计提交文件类型)


git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | grep "\(.html\|.java\|.xml\|.properties\|.css\|.js\|.txt\)$" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done


3、统计某时间范围内的代码提交量


git log --author=mengfanxiao --since=2019-01-01 --until=2021-02-01 --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | grep "\(.html\|.java\|.xml\|.properties\)$" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done


结果:added lines: 106243, removed lines: 14088, total lines: 92155


4、查看git提交前5名


git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5


项目代码行数统计_git


5、贡献值统计


git log --pretty='%aN' | sort -u | wc -l


6、提交数统计


git log --oneline | wc -l



7、统计或修改的行数


git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/'



二、idea statstic 统计


1、安装statstic插件


项目代码行数统计_html_02

2、安装插件

项目代码行数统计_xml_03

3、已安装好的效果 然后重启下idea

项目代码行数统计_xml_04

4、重启了之后 就会出现stastic 选中要查看的代码 点击 refresh on selection 

项目代码行数统计_git_05

5、overview是全部文件  其他的tab页签 如css html java js properties txt xml 可以配置

项目代码行数统计_git_06

6、配置方式 

1)点击settings 

项目代码行数统计_git_07

2)配置文件类型

项目代码行数统计_git_08

三、gitstat (感觉最有意思的方式)


git clone git://github.com/hoxu/gitstats.git

cd gitstats

./gitstats 你的项目的位置 生成统计的文件夹位置


可能会提示没有安装gnuplot画图程序,那么需要安装再执行:


//mac osx
brew install gnuplot
//centos linux
yum install gnuplot


用mac brew安装的时候 速度可能很慢 处理方式


更换国内阿里云上的homebrew镜像:

 

# 替换brew.git:

cd "$(brew --repo)"

git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

# 替换homebrew-core.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

# 替换homebrew-bottles:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc

source ~/.zshrc


切换好安装源之后 再使用brew命令就会分块



安装好之后 执行命令

项目代码行数统计_git_09


就会生成html文档

项目代码行数统计_git_10


访问页面 首先看到项目概括 总文件、代码总行数、总提交次数、多少个作者

项目代码行数统计_xml_11

提交记录


项目代码行数统计_xml_12


作者提交记录统计

项目代码行数统计_xml_13

项目代码行数统计_xml_14

项目代码行数统计_git_15

项目代码行数统计_git_16


四、使用 cloc 


1、

brew install cloc

项目代码行数统计_html_17

2、统计当前文件夹代码量

项目代码行数统计_xml_18

3、统计排除当前目录下的某个文件夹的代码量(这里以Pods文件夹为例)


cloc ./ --exclude-dir=Pods


3、统计特定文件的代码量(这里以acpi为例)


cloc -by-file acpi


4、帮助文档


项目代码行数统计_git_19


举报

相关推荐

0 条评论