Git:如何根据添加/更改的代码行来估算某个人对我的项目的贡献? [英] Git: How to estimate a contribution of a person to my project in terms of added/changed lines of code?

查看:120
本文介绍了Git:如何根据添加/更改的代码行来估算某个人对我的项目的贡献?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GIT存储库,我想计算一段时间内一个人或一群人添加/更改了多少行代码。你可以使用 git log 是否可以使用git来计算?

解决方案 >和一些shell-fu:

  git log --shortstat --authorAviv Ben-Yosef--since2几周前--until1周前\ 
| grepfiles \?changed\
| awk'{files + = $ 1;插入+ = $ 4;删除+ = $ 6} END \
{打印文件已更改,文件,插入的行:,已插入,已删除行,已删除}'
pre>

解释: git log --shortstat 显示每个提交的简短统计信息,显示更改的文件数量,插入和删除的行数。然后,我们可以为特定的提交者( - 作者您的姓名)和时间范围( - 自2周前 --until1 week ago)。



现在,为了实际总结统计数据,我们做一些shell脚本来完成它。首先,我们使用 grep 来仅过滤含有差异的行。这些行如下所示:

  8个文件已更改,169个插入(+),81个删除( - )

或此:

  1个文件改变了,4个插入(+),4个删除( - )

awk :对于每一行,我们添加已更改的文件(第1个字),插入的行(第4个字)和删除的行(第6个字),然后在总结。



编辑:正斜杠添加在顶部片段中,因此可以复制并粘贴到命令行中。


I have a GIT repository and I want to calculate how many lines of code were added/changed by one person or a group of persons during some period of time. Is it possible to calculate with git?

解决方案

You can use git log and some shell-fu:

git log --shortstat --author "Aviv Ben-Yosef" --since "2 weeks ago" --until "1 week ago" \
    | grep "files\? changed" \
    | awk '{files+=$1; inserted+=$4; deleted+=$6} END \
           {print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'

Explanation: git log --shortstat displays a short statistic about each commit, which, among other things, shows the number of changed files, inserted and deleted lines. We can then filter it for a specific committer (--author "Your Name") and a time range (--since "2 weeks ago" --until "1 week ago").

Now, in order to actually sum up the stats instead of seeing the entry per commit, we do some shell scripting to do it. First, we use grep to filter only the lines with the diffs. These lines look like this:

 8 files changed, 169 insertions(+), 81 deletions(-)

or this:

 1 file changed, 4 insertions(+), 4 deletions(-)

We then sum these using awk: for each line we add the files changed (1st word), inserted lines (4th word) and deleted lines (6th word) and then print them after summing it all up.

Edit: forward slashes were added in the top snippet so it can be copy and pasted into a command line.

这篇关于Git:如何根据添加/更改的代码行来估算某个人对我的项目的贡献?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆