【转载】Git Log pretty用法

选项参数语法:

--pretty=format:%ae


详细使用教程https://www.cnblogs.com/wutou/p/17490984.html
--pretty=format控制显示信息的颜色:https://www.cnblogs.com/wutou/p/17536218.html


注意:某些参数,老版本 git 可能不支持


选项(参数)说明速记(备注、示例)
%H 提交的完整哈希值(40位ID值) commit hash
%h 提交的简写哈希值(8位ID值) Abbreviated commit hash
%T 树的完整哈希值 tree hash
%t 树的简写哈希值 Abbreviated tree hash
%P 父提交的完整哈希值 Parent hashes
%p 父提交的简写哈希值 Abbreviated parent hashes
%an 作者(author)的名字  
%aN mailmap中对应的作者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))  
%ae 作者邮箱  
%aE 作者邮箱 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))  
%ce 提交者 email  
%cE 提交者 email (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))  
%ad 日期 (–date= 制定的格式) Thu Aug 3 10:33:01 2023 +0800
%aD 日期, RFC2822格式 Thu, 3 Aug 2023 10:33:01 +0800
%ah 提交星期、月、日、时、分 Wed Jun 28 18:24
%ch 提交星期、月、日、时、分 Wed Jun 28 18:24
%ar 日期, 相对格式(1 day ago) 8 天前
%at 日期, UNIX timestamp 1691029981
%ai 日期, ISO 8601 格式 2023-08-03 10:33:01 +0800
%aI 日期 2023-06-28T18:24:01+08:00
%as 提交日期 2023-09-13
%cs 提交日期 2023-09-13
%cd 提交日期 (--date= 制定的格式) Thu Aug 3 10:33:01 2023 +0800
%cD 提交日期, RFC2822格式 Thu, 3 Aug 2023 10:33:01 +0800
%ci 提交日期, ISO 8601 格式 2023-08-03 10:33:01 +0800
%cI 提交日期 2023-06-28T18:24:01+08:00
%cr 提交日期, 相对格式(1 day ago) 8 天前
%ct 提交日期, UNIX timestamp(从1970年1月1日起走过的秒数)
换算方法:1687947841/60秒/60分/24小时/365天,约等于 53.6年
1687947841(2023-06-28 18:24:01)
%al 提交者名字 Author  
%an 提交者名字 Author  
%cl 提交者名字 Author  
%cn 提交者(committer)的名字  
%cN 提交者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))  
%d 显示ref,分支、tag 名称,带括号 (HEAD -> refs/heads/n)
%D 显示ref,分支、tag 名称,不带括号 HEAD -> refs/heads/n
%e encoding  
%s 提交说明,单行显示 subject
%S   HEAD
%B 提交说明,多行显示,保留回车换行 subject
%b commit信息内容  
%f 提交说明第一行内容(中文不显示)。过滤commit信息的标题使之可以作为文件名  
%N commit notes  
%n 换行(打印 空行)  
%gD reflog selector, e.g., refs/stash@  
%gd shortened reflog selector, e.g., stash@  
%gE    
%gN    
%gs reflog subject  
%GF    
%GG    
%GK    
%GP    
%GS    
%GT    
%m 左,右或边界标记。left, right or boundary mark >
%% a raw %  
%x00 print a byte from a hex code  
%w([<w>[,<i1>[,<i2>]]]) switch line wrapping, like the -w option of git-shortlog(1).  
%<|(num) 设置占位宽度,左对齐 设置提交时间占用19字符宽度:%<|(19)%as
%>|(num) 设置占位宽度,右对齐 设置提交时间占用19字符宽度:%>|(19)%as
%<(N, trunc) 下一个单元的输出宽度限制为N列, 左对齐  
%<|(N, trunc) 下一个单元输出至全局第N列, 左对齐  
%> 右对齐  
%> 右对齐  
%>> 右对齐 (如果左边有多余空格则复用)  
%>< 居中对齐  
%x08 即\b 为了把截断产生的"."删除


   

git log -xx --xxxx 参数【汇总】 https://www.cnblogs.com/wutou/p/17581606.html



遍历

有些变量,官方并没有提供,只能遍历出值,来确定作用

  for i in {a..z};do for j in {a..z};do echo "$i$j=$(git log -1 --pretty=format:%$i$j)"; done; done
  for i in {a..z};do for j in {A..Z};do echo "$i$j=$(git log -1 --pretty=format:%$i$j)"; done; done
  for i in {A..Z};do for j in {A..Z};do echo "$i$j=$(git log -1 --pretty=format:%$i$j)"; done; done

为什么不直接用{a..Z}? 因为会报错,所以只能分开



Git 官方说明大全:

中文版:https://git-scm.com/book/zh/v2/Git-基础-查看提交历史#pretty_format
英文版:https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History

https://git-scm.com/docs (git 官方 docs 说明大全,英文版)
http://static.kancloud.cn/apachecn/git-doc-zh/  (看云-Git中文参考)

 



 

作者:悟透

原文链接:https://www.cnblogs.com/wutou/p/17538388.html

来源:博客园

著作权归原作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

posted @ 2025-03-26 13:55  獠牙  阅读(52)  评论(0)    收藏  举报