哪些 Git 提交统计信息很容易获取

发布于 2024-08-05 19:47:25 字数 169 浏览 4 评论 0原文

以前我很喜欢 TortoiseSvn 为给定 SVN 存储库生成简单提交统计信息的能力。我想知道 Git 中有哪些功能,并且特别感兴趣的是:

  • 每个用户的提交数量
  • 每个用户活动随时间变化的行数
  • (例如每周汇总的变化)

有什么想法吗?

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 :

  • Number of commits per user
  • Number of lines changed per user
  • activity over time (for instance aggregated weekly changes)

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

黒涩兲箜 2024-08-12 19:47:26

修改https://stackoverflow.com/a/18797915/3243930
。输出结果与github上的图数据非常接近。

#!/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("\t")
  next if parts.size == 0
  if parts[0].match(/[a-zA-Z]+|[^\u0000-\u007F]+/)
    if who
      map[who][0] += memo[0]
      map[who][1] += memo[1]
      if memo[0] > 0 || memo[1] > 0 
        map[who][2] += 1
      end
    end
    who = parts[0]
    memo = [0,0]
    next
  end
  if who
    memo[0]+=parts[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")

Modify https://stackoverflow.com/a/18797915/3243930
. the output is much closed to the graph data of github.

#!/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("\t")
  next if parts.size == 0
  if parts[0].match(/[a-zA-Z]+|[^\u0000-\u007F]+/)
    if who
      map[who][0] += memo[0]
      map[who][1] += memo[1]
      if memo[0] > 0 || memo[1] > 0 
        map[who][2] += 1
      end
    end
    who = parts[0]
    memo = [0,0]
    next
  end
  if who
    memo[0]+=parts[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")
五里雾 2024-08-12 19:47:25

实际上,git 已经有一个用于此目的的命令:

git shortlog

在您的情况下,听起来您对这种形式感兴趣:

git shortlog -sne

请参阅 --help 了解各种选项。

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

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

  • 一般统计信息:总文件数、行数、提交数、作者数。
  • 活动:按一天中的小时、一周中的一天、一周中的小时、一年中的月份、年月和年进行提交。
  • 作者:作者列表(姓名、提交次数 (%)、首次提交日期、上次提交日期、年龄)、月份作者、年份作者。
  • 文件:按日期、扩展名的文件计数
  • 行:按日期的代码行数

Actually, git already has a command for this:

git shortlog

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

git shortlog -sne

See the --help for various options.

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:

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
空气里的味道 2024-08-12 19:47:25

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

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

您要求的其他统计数据可能需要更多考虑。您可能想查看可用的工具。谷歌搜索 git stats 指向 GitStats 工具,我没有这方面的经验,更不知道如何让它在 Windows 上运行,但你可以尝试一下。

First, you don't have to pull anything (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[$0]; } 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 statistics points to the GitStats tool, which I have no experience with and even less idea of what it takes to get it run on windows, but you can try.

も星光 2024-08-12 19:47:25

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

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

npm install -g gitinspector

详细信息以获取链接如下

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

示例命令

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

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

You can install like below with npm

npm install -g gitinspector

Details to get the links are below

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

example commands are

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

etc

逐鹿 2024-08-12 19:47:25

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

git log --pretty=format:%an \
| awk '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }'\
| sort -r

使用 awk,因为我的 mac 上没有 gawk,并在顶部按最活跃的提交者进行排序。)
它输出一个像这样的列表:

 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

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

git log --pretty=format:%an \
| awk '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }'\
| sort -r

(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:

 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
七月上 2024-08-12 19:47:25

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

[$]> 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

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

[$]> 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
书信已泛黄 2024-08-12 19:47:25

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

这里的关键是执行 HASH..HASH 的能力,

下面我使用从分支到 HEAD(该分支的末尾)的第一个哈希。

显示分支中的总提交

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

显示每个作者的总提交

  • git Shortlog FIRST_HASH..HEAD -sne
  • 输出
  • 24 作者姓名
  • 9 作者姓名

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

key here is the ability to do HASH..HASH

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

Show total commits in a branch

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

Show total commits per author

  • git shortlog FIRST_HASH..HEAD -sne
  • Output
  • 24 Author Name
  • 9 Author Name
时光磨忆 2024-08-12 19:47:25

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

其中包括:

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"

That would include:

度的依靠╰つ 2024-08-12 19:47:25

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

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

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

​​gitstats-simple.rb 的内容

#!/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")

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.

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

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

contents of gitstats-simple.rb

#!/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")
迷途知返 2024-08-12 19:47:25

DataHero 现在可以轻松提取 Github 数据并获取统计信息。
我们在内部使用它来跟踪每个里程碑的进度。

https://datahero.com/partners/github/

我们如何在内部使用它:https://datahero.com/blog/2013/08/13/ Management-github-projects-with-datahero/

披露:我为 DataHero 工作

DataHero now makes it easy to pull in Github data and get stats.
We use it internally to track our progress on each milestone.

https://datahero.com/partners/github/

How we use it internally: https://datahero.com/blog/2013/08/13/managing-github-projects-with-datahero/

Disclosure: I work for DataHero

秋意浓 2024-08-12 19:47:25

您可以使用 gitlogged gem (https://github.com/dexcodeinc/gitlogged) 获取作者的活动和日期。这将为您提供如下报告:

gitlogged 2016-04-25 2016-04-26

返回以下输出

################################################################

Date: 2016-04-25

Yunan (4):
      fix attachment form for IE (#4407)
      fix (#4406)
      fix merge & indentation attachment form
      fix (#4394) unexpected after edit wo

gilang (1):
      #4404 fix orders cart


################################################################
################################################################

Date: 2016-04-26

Armin Primadi (2):
      Fix document approval logs controller
      Adding git tool to generate summary on what each devs are doing on a given day for reporting purpose

Budi (1):
      remove validation user for Invoice Processing feature

Yunan (3):
      fix attachment in edit mode (#4405) && (#4430)
      fix label attachment on IE (#4407)
      fix void method (#4427)

gilang (2):
      Fix show products list in discussion summary
      #4437 define CApproved_NR status id in order


################################################################

You can use gitlogged gem (https://github.com/dexcodeinc/gitlogged) to get activities by author and date. This will give you report like this:

gitlogged 2016-04-25 2016-04-26

which returns the following output

################################################################

Date: 2016-04-25

Yunan (4):
      fix attachment form for IE (#4407)
      fix (#4406)
      fix merge & indentation attachment form
      fix (#4394) unexpected after edit wo

gilang (1):
      #4404 fix orders cart


################################################################
################################################################

Date: 2016-04-26

Armin Primadi (2):
      Fix document approval logs controller
      Adding git tool to generate summary on what each devs are doing on a given day for reporting purpose

Budi (1):
      remove validation user for Invoice Processing feature

Yunan (3):
      fix attachment in edit mode (#4405) && (#4430)
      fix label attachment on IE (#4407)
      fix void method (#4427)

gilang (2):
      Fix show products list in discussion summary
      #4437 define CApproved_NR status id in order


################################################################
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文