前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Git log 统计分析

Git log 统计分析

作者头像
Yifans_Z
发布2023-08-23 18:39:53
2230
发布2023-08-23 18:39:53
举报

统计个人增删行数

代码语言:javascript
复制
git config user.name

git log --author="zhaoyifan" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
代码语言:javascript
复制
added lines: 82813, removed lines: 53707, total lines: 29106

统计每个人增删行数

代码语言:javascript
复制
git log --shortstat | grep -E "(Author: )(\s*(\w+)){2}|fil(e|es) changed" | awk '
{
 if($1 ~ /Author/) {
  author = $2" "$3
 } else {
  files[author]+=$1
  inserted[author]+=$4
  deleted[author]+=$6
 }
}
END { for (key in files) { print "Author: " key "\n\tfiles changed: ", files[key], "\n\tlines inserted: ", inserted[key], "\n\tlines deleted: ", deleted[key] } }
'

统计每个人提交次数

代码语言:javascript
复制
git shortlog -sn --no-merges

忽略某些路径的更改

代码语言:javascript
复制
git log -- . ":(exclude)sub"
git log -- . ":!sub"

cloc

AlDanial/cloc - cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

代码语言:javascript
复制
cloc source/

     186 text files.
     186 unique files.
       3 files ignored.

github.com/AlDanial/cloc v 1.84  T=0.16 s (1112.3 files/s, 138678.8 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Markdown                       183           6028              0          16788
-------------------------------------------------------------------------------
SUM:                           183           6028              0          16788
-------------------------------------------------------------------------------

Git Fame

Git Fame - A command-line tool that helps you summarize and pretty-print git collaborators based on contributions

代码语言:javascript
复制
gem install git_fame
cd /path/to/gitdir && git fame
Total number of files: 2,053
Total number of lines: 63,132
Total number of commits: 4,330

+------------------------+--------+---------+-------+--------------------+
| name                   | loc    | commits | files | percent            |
+------------------------+--------+---------+-------+--------------------+
| Johan Sørensen         | 22,272 | 1,814   | 414   | 35.3 / 41.9 / 20.2 |
| Marius Mathiesen       | 10,387 | 502     | 229   | 16.5 / 11.6 / 11.2 |
| Jesper Josefsson       | 9,689  | 519     | 191   | 15.3 / 12.0 / 9.3  |
| Ole Martin Kristiansen | 6,632  | 24      | 60    | 10.5 / 0.6 / 2.9   |
| Linus Oleander         | 5,769  | 705     | 277   | 9.1 / 16.3 / 13.5  |
| Fabio Akita            | 2,122  | 24      | 60    | 3.4 / 0.6 / 2.9    |
| August Lilleaas        | 1,572  | 123     | 63    | 2.5 / 2.8 / 3.1    |
| David A. Cuadrado      | 731    | 111     | 35    | 1.2 / 2.6 / 1.7    |
| Jonas Ängeslevä        | 705    | 148     | 51    | 1.1 / 3.4 / 2.5    |
| Diego Algorta          | 650    | 6       | 5     | 1.0 / 0.1 / 0.2    |
| Arash Rouhani          | 629    | 95      | 31    | 1.0 / 2.2 / 1.5    |
| Sofia Larsson          | 595    | 70      | 77    | 0.9 / 1.6 / 3.8    |
| Tor Arne Vestbø        | 527    | 51      | 97    | 0.8 / 1.2 / 4.7    |
| spontus                | 339    | 18      | 42    | 0.5 / 0.4 / 2.0    |
| Pontus                 | 225    | 49      | 34    | 0.4 / 1.1 / 1.7    |
+------------------------+--------+---------+-------+--------------------+

让 git log 的输出漂亮简洁

代码语言:javascript
复制
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an %ae>%Creset' --abbrev-commit"

https://gist.github.com/johanmeiring/3002458

~/.gitconfig 看到:

代码语言:javascript
复制
[alias]
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an %ae>%Creset' --abbrev-commit

这其中的占位符的解释:

  • %Cred:将颜色设置为红色
  • %Creset:重置颜色
  • %C(yellow):将颜色设置为黄色
  • %h:缩略的提交哈希值
  • %d:ref names(不知道该怎么解释 😆)
  • %s:提交时的 message
  • %cr:相对的提交时间。可以换成%ci,展示的是年月日时分秒。
  • %an:提交人的 name
  • %ae:提交人的邮箱

更多占位符,可以参考官方文档:https://git-scm.com/docs/pretty-formats

References

– EOF –

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-3,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 统计个人增删行数
  • 统计每个人增删行数
  • 统计每个人提交次数
  • 忽略某些路径的更改
  • cloc
  • Git Fame
  • 让 git log 的输出漂亮简洁
  • References
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档