20

我刚刚安装了GitStats,此时我不得不说,“现在,什么?”。我在用户代码行等网站上看到了示例,但没有关于如何获取此类简单统计信息的示例。我不需要图表或任何东西。我只是希望能够在用户列表中控制台输出结果-> 代码行或其他内容。任何帮助深表感谢。

4

1 回答 1

32

更新(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

它输出带有图表、通过选项卡导航等的整个报告。

注意:你无法知道每个用户贡献了多少行(至少对于apt-get install gitstats我得到的 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()
于 2012-02-15T22:49:27.677 回答