哪些 Git 提交统计数据很容易提取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1486819/
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-10 07:07:42  来源:igfitidea点击:

Which Git commit stats are easy to pull

gitstatisticsloggingcode-statistics

提问by Jesper R?nn-Jensen

Previously I have enjoyed TortoiseSvn's ability to generate simple commit stats for a given SVN repository. I wonder what is available in Git and am particularly interested in :

以前我很喜欢 TortoiseSvn 为给定 SVN 存储库生成简单提交统计信息的能力。我想知道 Git 中有什么可用,并且对以下内容特别感兴趣:

  • Number of commits per user
  • Number of lines changed per user
  • activity over time (for instance aggregated weekly changes)
  • 每个用户的提交次数
  • 每个用户更改的行数
  • 一段时间内的活动(例如每周汇总的变化)

Any ideas?

有任何想法吗?

回答by Pat Notz

Actually, git already has a command for this:

实际上,git 已经有一个命令:

git shortlog

in your case, it sounds like you're interested in this form:

就您而言,听起来您对这种形式感兴趣:

git shortlog -sne

See the --helpfor various options.

有关--help各种选项,请参阅。

You may also be interested in the GitStats project. They have a few examples, including the stats for the Git project. From the GitStat main page:

您可能还对GitStats 项目感兴趣。他们有一些示例,包括Git 项目统计信息。从 GitStat 主页:

Here is a list of some statistics generated currently:

以下是当前生成的一些统计信息的列表:

  • General statistics: total files, lines, commits, authors.
  • Activity: commits by hour of day, day of week, hour of week, month of year, year and month, and year.
  • Authors: list of authors (name, commits (%), first commit date, last commit date, age), author of month, author of year.
  • Files: file count by date, extensions
  • Lines: Lines of Code by date
  • 一般统计信息:总文件数、行数、提交数、作者数。
  • 活动:按一天中的某个小时、一周中的某天、一周中的某个小时、年中的月份、年和月以及年进行提交。
  • 作者:作者列表(姓名、提交次数 (%)、首次提交日期、最后提交日期、年龄)、月份作者、年份作者。
  • 文件:按日期、扩展名的文件计数
  • 行:按日期排列的代码行

回答by Michael Krelin - hacker

First, you don't have to pullanything (as in network pull), because you have the whole repository and the whole history locally. I'm pretty sure there are tools that will give you statistics, but sometimes you can just be creative with the command lines. For instance, this (just out of my head) will give you the number of commits per user:

首先,您不必任何东西(如网络拉),因为您在本地拥有整个存储库和整个历史记录。我很确定有一些工具可以为您提供统计数据,但有时您可以通过命令行发挥创意。例如,这(刚刚超出我的脑海)将为您提供每个用户的提交次数:

git log --pretty=format:%ae \
| gawk -- '{ ++c[
npm install -g gitinspector
]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }'

Other statistics you asked for may need more thought put into it. You may want to see the tools available. Googling for git statisticspoints to the GitStatstool, which I have no experience with and even less idea of what it takes to get it run on windows, but you can try.

您要求的其他统计数据可能需要更多考虑。您可能想查看可用的工具。谷歌搜索git statisticsGitStats工具的点数,我没有经验,甚至不知道在 Windows 上运行它需要什么,但你可以尝试。

回答by Ravikiran Reddy Kotapati

The best tool so far I identfied is gitinspector. It give the set report per user, per week etc

迄今为止我发现的最好的工具是 gitinspector。它为每个用户、每周等提供设置报告

You can install like below with npm

您可以使用 npm 进行如下安装

https://www.npmjs.com/package/gitinspector
https://github.com/ejwa/gitinspector/wiki/Documentation
https://github.com/ejwa/gitinspector

Details to get the links are below

获取链接的详细信息如下

gitinspector -lmrTw
gitinspector --since=1-1-2017

example commands are

示例命令是

git log --pretty=format:%an \
| awk '{ ++c[
 1205 therikss
 1026 lsteinth
  771 kmoes
  720 minielse
  507 pagerbak
  269 anjohans
  205 mfoldbje
  188 nstrandb
  133 pmoller
   58 jronn
   10 madjense
    3 nlindhol
    2 shartvig
    2 THERIKSS
]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }'\ | sort -r

etc

等等

回答by Jesper R?nn-Jensen

Thanks to hacker for answering this question. However, I found these modified versions to be better for my particular usage:

感谢黑客回答这个问题。但是,我发现这些修改后的版本更适合我的特定用途:

[$]> git merge-stats
% of Total Merges               Author  # of Merges  % of Commits
            57.14     Daniel Beardsley            4          5.63
            42.85        James Pearson            3         30.00

(using awk as I don't have gawk on my mac, and sorting with most active comitter on top.) It outputs a list like so:

(使用 awk,因为我的 mac 上没有 gawk,并使用最活跃的提交者进行排序。)它输出如下列表:

git log --numstat --pretty='%an' | ruby gitstats-simple.rb

回答by jhanifen

Here are ways to get stats for a specific branch or two hashs.

以下是获取特定分支或两个哈希的统计信息的方法。

key here is the ability to do HASH..HASH

这里的关键是能够做 HASH..HASH

Below I am using the first hash from a branch to the HEAD which is the end of that branch.

下面我使用从一个分支到 HEAD 的第一个散列,这是该分支的结尾。

Show total commits in a branch

显示分支中的总提交

  • git log FIRST_HASH..HEAD --pretty=oneline | wc -l
  • Output 53
  • git log FIRST_HASH..HEAD --pretty=oneline | wc -l
  • 输出 53

Show total commits per author

显示每位作者的提交总数

  • git shortlog FIRST_HASH..HEAD -sne
  • Output
  • 24 Author Name
  • 9 Author Name
  • git shortlog FIRST_HASH..HEAD -sne
  • 输出
  • 24 作者姓名
  • 9 作者姓名

回答by VonC

Note that, if your repo is on GitHub, you now (May 2013) have a new set of GitHub API to get interesting statistics.
See "File CRUD and repository statistics now available in the API"

请注意,如果您的存储库位于 GitHub 上,那么您现在(2013 年 5 月)就有了一组新的 GitHub API 来获取有趣的统计数据。
请参阅“ API 中现在可用的文件 CRUD 和存储库统计信息

That would include:

这将包括:

回答by Xiong Chiamiov

I've written a small shell scriptthat calculates merge statistics (useful when dealing with a feature-branch-based workflow). Here's an example output on a small repository:

我编写了一个计算合并统计数据的小 shell 脚本(在处理基于特征分支的工作流时很有用)。这是一个小型存储库上的示例输出:

#!/usr/bin/ruby

# takes the output of this on stdin: git log --numstat --prety='%an'

map = Hash.new{|h,k| h[k] = [0,0,0]}
who = nil
memo = nil
STDIN.read.split("\n").each do |line|
  parts = line.split
  next if parts.size == 0
  if parts[0].match(/[a-z]+/)
    if who && memo[0] + memo[1] < 2000
      map[who][0] += memo[0]
      map[who][1] += memo[1]
      map[who][2] += 1
    end
    who = parts[0]
    memo = [0,0]
    next
  end
  if who
    memo[0]+=line[0].to_i
    memo[1]+=parts[1].to_i
  end
end

puts map.to_a.map{|x| [x[0], x[1][0], x[1][1], x[1][2]]}.sort_by{|x| -x[1] - x[2]}.map{|x|x.inspect.gsub("[", "").gsub("]","")}.join("\n")

回答by Lee jung.seung

回答by Cliff Frey

Here is a simple ruby script that I used to get author, lines added, lines removed, and commit count from git. It does not cover commits over time.

这是一个简单的 ruby​​ 脚本,我用来从 git 获取作者、添加行、删除行和提交计数。它不包括随着时间的推移提交。

Note that I have a trick where it ignores any commit that adds/removes more than 10,000 lines because I assume that this is a code import of some sort, feel free to modify the logic for your needs. You can put the below into a file called gitstats-simple.rb and then run

请注意,我有一个技巧,它会忽略任何添加/删除超过 10,000 行的提交,因为我认为这是某种代码导入,可以根据需要随意修改逻辑。您可以将以下内容放入名为 gitstats-simple.rb 的文件中,然后运行

##代码##

contents of gitstats-simple.rb

gitstats-simple.rb 的内容

##代码##

回答by Ben

If you are using github, PR Countis a github app built for showing contribution stats.

如果您使用 github,PR Count是一个 github 应用程序,用于显示贡献统计信息。