如何使用 gitstats 找出 Git 存储库和每个提交者总共有多少 SLOC?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9301759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:29:29  来源:igfitidea点击:

How can I use gitstats to find out how many SLOC a Git repo has in total and per commiter?

gitcode-statistics

提问by orokusaki

I just installed GitStats, and I'm at that point where I have to say, "Now, what?". I see examples on the site of user lines of code, etc., but no examples of how to get simple stats like that. I don't need a chart or anything. I just want to be able to console output the results in a list of user -> lines of code or something. Any help is much appreciated.

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

回答by orokusaki

Update (July 11th, 2014)

更新(2014 年 7 月 11 日)

I'm not sure what version i had installed when I first answered this question, but the latest version gave me an authors.htmlfile when I ran gitstats /path/to/repo/.git /path/to/output/dir/that contained exactly the info I was looking for.

我不确定我第一次回答这个问题时安装了什么版本,但是authors.html当我运行时,最新版本给了我一个文件,gitstats /path/to/repo/.git /path/to/output/dir/其中包含我正在寻找的信息。

Original Answer

原答案

It's pretty simple, I found. You just type:

这很简单,我发现。你只需输入:

gitstats /path/to/the/repo.git --outputpath=directory_where_you_want_the_output

It outputs the entire report with charts, navigation via tabs, etc.

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

Note: You cannot tell how many lines each user has contributed (at least with the version of gitstats that an apt-get install gitstatsgot me). The output was useful, and is a great way to learn about your code base and its contributors. I did the following, to get the number of lines of a particular user:

注意:您无法确定每个用户贡献了多少行(至少对于apt-get install gitstats我得到的 gitstats 版本)。输出很有用,是了解代码库及其贡献者的好方法。我执行了以下操作,以获取特定用户的行数:

git log --author="Some Author <[email protected]>" --oneline --shortstat > some_author.txt

Then, I used Python to parse the data (since there were hundreds of commits):

然后,我使用 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()