【Git】Git 统计常用命令

目录

一. 问题

二. 命令

1. git shortlog 命令

2. git show-ref 命令

3. git log 命令

4. git rev-list 命令

5. git ls-tree 命令

6. git cat-file 命令

三. 参考

四. 测试用例


一. 问题

最近学习Python 的过程中,看了看网上的语法和相关基础知识,看了好多,也忘了好多,觉得用处不大,好记性不如烂笔头,拿一个项目来锻炼一下下,验证下自己的Python 技术功底;

有些中间用到的命令,有些借助了机器翻译,难免有些疏漏和不足之处,倾尽谅解,持续性汇总一下,方便以后查阅和记忆;

持续性更新...

二. 命令

1. git shortlog 命令

具体git shortlog 是用来干啥的?

简单理解就是汇总git日志输出; 

git shortlog [<options>] [<revision range>] [[--] <path>…​]
git log --pretty=short | git shortlog [<options>]


-n // 根据每个作者的提交次数(而不是作者字母顺序)对输出进行排序。
-s // 禁止提交描述,仅提供提交计数摘要。
-e // 显示每个作者的电子邮件地址。

举例:

$ git shortlog -s --since="2020-01-10" "HEAD"

or

$ git shortlog -s --since="2020-01-13..2020-01-08" "HEAD"

or

$ git shortlog -s --since="2020-01-08" --until="2020-01-13" "HEAD"

$ git shortlog -s --tags "HEAD"

2. git show-ref 命令

简单理解就是列出本地存储库中的引用;

git show-ref [-q|--quiet] [--verify] [--head] [-d|--dereference]
	     [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags]
	     [--heads] [--] [<pattern>…​]
git show-ref --exclude-existing[=<pattern>]

举例:

$ git show-ref --head --dereference
$ git show-ref --heads --tags

3. git log 命令

显示提交的log 信息

git log [<options>] [<revision range>] [[--] <path>…​]


--shortstat // 仅输出 '--stat' 包含已修改文件总数以及添加和删除行数的格式的最后一行

该命令具有适用于该git rev-list 命令的选项以控制显示内容和方式,以及适用于该git diff-*命令的选项以控制如何显示每次提交引入的更改;

基本格式化信息,如下:


%H: commit hash
%h: 缩短的commit hash
%T: tree hash
%t: 缩短的 tree hash
%P: parent hashes
%p: 缩短的 parent hashes
%an: 作者名字
%aN: mailmap的作者名字 (.mailmap对应,详情参照[git-shortlog(1)](http://linux.die.net/man/1/git-shortlog)或者[git-blame(1)](http://linux.die.net/man/1/git-blame))
%ae: 作者邮箱
%aE: 作者邮箱 (.mailmap对应,详情参照[git-shortlog(1)](http://linux.die.net/man/1/git-shortlog)或者[git-blame(1)](http://linux.die.net/man/1/git-blame))
%ad: 日期 (--date= 制定的格式)
%aD: 日期, RFC2822格式
%ar: 日期, 相对格式(1 day ago)
%at: 日期, UNIX timestamp
%ai: 日期, ISO 8601 格式
%cn: 提交者名字
%cN: 提交者名字 (.mailmap对应,详情参照[git-shortlog(1)](http://linux.die.net/man/1/git-shortlog)或者[git-blame(1)](http://linux.die.net/man/1/git-blame))
%ce: 提交者 email
%cE: 提交者 email (.mailmap对应,详情参照[git-shortlog(1)](http://linux.die.net/man/1/git-shortlog)或者[git-blame(1)](http://linux.die.net/man/1/git-blame))
%cd: 提交日期 (--date= 制定的格式)
%cD: 提交日期, RFC2822格式
%cr: 提交日期, 相对格式(1 day ago)
%ct: 提交日期, UNIX timestamp
%ci: 提交日期, ISO 8601 格式
%d: ref名称
%e: encoding
%s: commit信息标题
%f: sanitized subject line, suitable for a filename
%b: commit信息内容
%N: commit notes
%gD: reflog selector, e.g., refs/stash@{1}
%gd: shortened reflog selector, e.g., stash@{1}
%gs: reflog subject
%Cred: 切换到红色
%Cgreen: 切换到绿色
%Cblue: 切换到蓝色
%Creset: 重设颜色
%C(...): 制定颜色, as described in color.branch.* config option
%m: left, right or boundary mark
%n: 换行
%%: a raw %
%x00: print a byte from a hex code
%w([[,[,]]]): switch line wrapping, like the -w option of git-shortlog(1).

举例:

$ git log HASH --pretty=format:"%at %aN %s" -n 1

$ git log --shortstat --first-parent -m --pretty=format:"%at %aN" --since="2020-01-08" --until="2020-01-13" "HEAD"

4. git rev-list 命令

以相反的时间顺序列出提交对象

git rev-list [<options>] <commit>…​ [[--] <path>…​]

举例:

$ git rev-list --pretty=format:"%at %ai %aN <%aE> '%s'" --since="2020-01-08" --until="2020-01-13" "HEAD" 

5. git ls-tree 命令

列出树对象的内容

git ls-tree [-d] [-r] [-t] [-l] [-z]
	    [--name-only] [--name-status] [--full-name] [--full-tree] [--abbrev[=<n>]]
	    <tree-ish> [<path>…​]

举例:

$ git ls-tree -r --name-only HASH

6. git cat-file 命令

提供存储库对象的内容或类型和大小信息

git cat-file (-t [--allow-unknown-type]| -s [--allow-unknown-type]| -e | -p | <type> | --textconv | --filters ) [--path=<path>] <object>
git cat-file (--batch | --batch-check) [ --textconv | --filters ] [--follow-symlinks]

举例:

$ git cat-file blob HASH

三. 参考

  1. https://git-scm.com/doc
  2. https://git-scm.com/docs/git-shortlog
  3. https://git-scm.com/docs/git-show-ref
  4. https://git-scm.com/docs/git-log
  5. https://git-scm.com/docs/git-rev-list
  6. https://git-scm.com/docs/git-ls-tree
  7. https://git-scm.com/docs/git-cat-file
  8. Git 基础 - 查看提交历史
  9. https://www.liaoxuefeng.com/wiki/896043488029600
  10. https://www.w3cschool.cn/doc_git/

四. 测试用例

### Git 测试脚本

$ git shortlog -s --since="2020-01-08" "HEAD"

$ git shortlog -s --since="2020-01-13..2020-01-08" "HEAD"

$ git shortlog -s --since="2020-01-08" --until="2020-01-13" "HEAD"

$ git show-ref --tags

$ git log "b76da094137669d3eb3edc985391366bc2bb93b9" --pretty=format:"%at %aN %s" -n 1

$ git shortlog -s "v0.0.1"

$ git rev-list --pretty=format:"%at %ai %aN <%aE>" --since="2020-01-08" "HEAD" | grep -v ^commit

$ git rev-list --pretty=format:"%at %ai %aN <%aE> " --since="2020-01-08" --until="2020-01-13" "HEAD" 

$ git rev-list --pretty=format:"%at %ai %aN <%aE>" --since="2020-01-08" --until="2020-01-13" "HEAD" | grep -v ^commit

$ git rev-list --pretty=format:"%at %ai %aN <%aE> '%s'" --since="2020-01-08" --until="2020-01-13" "HEAD" 

$ git ls-tree -r --name-only "b44c7cceaf24cb1f625dbcda5a7e69543b385a25"

$ git cat-file blob 26b26d60c30993215f02ba945593555c1811469b

$ git log --shortstat --first-parent -m --pretty=format:"%at %aN" --since="2020-01-08" --until="2020-01-13" "HEAD"






发布了66 篇原创文章 · 获赞 17 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/DovSnier/article/details/103955982