我如何使用gitstats找出总计和每个概述的git回购库有多少个sloc? [关闭
-
25-10-2019 - |
题
我刚刚安装 Gitstats, ,那时我不得不说:“现在,什么?”。我在代码等用户行的网站上看到了示例,但是没有关于如何获得这样的简单统计信息的示例。我不需要图表或任何图表。我只想能够在用户 - >“代码线”或其他内容的列表中委托将结果输出。任何帮助深表感谢。
解决方案
更新(2014年7月11日)
我不确定我第一次回答这个问题时安装了什么版本,但最新版本给了我一个 authors.html
我跑了 gitstats /path/to/repo/.git /path/to/output/dir/
这完全包含我正在寻找的信息。
原始答案
我发现这很简单。您只键入:
gitstats /path/to/the/repo.git --outputpath=directory_where_you_want_the_output
它以图表,通过选项卡的导航等输出整个报告,等等。
注意:您无法分辨每个用户贡献了多少行(至少使用Gitstats的版本 apt-get install gitstats
得到我)输出很有用,是了解您的代码库及其贡献者的好方法。我做了以下操作,以获取特定用户的行数:
git log --author="Some Author <Some.Author@example.com>" --oneline --shortstat > some_author.txt
然后,我使用Python来解析数据(因为有数百个提交):
>>> import re
>>> file = open('some_author.txt', 'r')
>>> adds, dels = 0, 0
>>> for line in file.readlines():
... am, dm = re.search(r'\d+(?= insertions)', line), re.search(r'\d+(?= deletions)', line)
... if am is not None:
... adds += int(am.group())
... dels += int(dm.group())
...
>>> adds, dels
(5036, 1653)
>>> file.close()
不隶属于 StackOverflow