git log 计算代码量

1. 统计提交的作者
   git log --pretty='%aN' | sort | uniq -c |awk '{print $2}'
2. 统计代码量
   git log --author="uer_name" --since ==2017-05-11 --until=2018-03-07 --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -

3. 使用图形化工具

安装gitstatus
     git clone git://github.com/hoxu/gitstats.git
     cd gitstats
     ./gitstats 你的项目的位置 生成统计的文件夹位置

生成的 html文件可web上打开index.html

4,统计每次的提交的commit ID,author email,日期

git log --pretty=format:"%H:%cd:%ce" --date=short

 

代码实现计算每个author在指定的时间的提交代码统计或每个commit 的代码修改量统计

#!/usr/bin/env bash

START_TIME=2012-01-01
END_TIME=2012-01-11

#count code by author
function count_author()
{
  authors=$(git log --pretty='%aN' | sort | uniq -c |awk '{print $2}')
  for user in $authors
  do   
     echo "<$user> `git log --author=$user --since ==$START_TIME --until=$END_TIME --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s ;removed lines: %s ;total lines: %s\n",add,subs,loc }' -`"

  done
  echo "<TOTAL> `git log --since ==$START_TIME --until=$END_TIME --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s ;removed lines: %s ;total lines: %s\n",add,subs,loc }' -`"
}

#count code by per commit
function count_per_commit()
{
  all_commits=$(git log --since ==$START_TIME --until=$END_TIME --pretty=format:"%H:%cd:%ce:" --date=short)
  for commit in $all_commits
  do 
      commit_id=$(echo "$commit"|awk -F ":" '{print $1}')
      commit_date=$(echo "$commit"|awk -F ":" '{print $2}')
      commit_email=$(echo "$commit"|awk -F ":" '{print $3}')
  echo "<$commit_email>--<$commit_date>-- `git show $commit_id  --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s ;removed lines: %s ;total lines: %s\n",add,subs,loc }' -`"

  done  
}

count_author
count_per_commit

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值