天堂1111 发表于 2018-1-15 17:20:17

git查看日志

git查看日志
  git log -n
  
显示前N条记录
  

git log -3  

  退出log命令
  
直接输入: q
  git log --stat -n
  
显示提交的文件的简要的修改统计
  

$ git log --stat -2  
commit d0b9a20fac8abc7517c5a04c0fbb1d488f309bf5
  
Author: BeginMan <pythonsuper@gmail.com>
  
Date:   Sat Mar 1 23:26:43 2014 +0800
  

  ok
  

  _posts/2014-02-27-Customizing-Git.md | 5 +++++
  1 file changed, 5 insertions(+)
  

  
commit 8c186cd71492b7a3eae6df7de880b99efa0f87cf
  
Author: BeginMan <pythonsuper@gmail.com>
  
Date:   Sat Mar 1 23:26:10 2014 +0800
  

  mi
  

  _posts/2014-02-27-Customizing-Git.md | 56 +++++++++++++++++++++++++++++++++++-
  1 file changed, 55 insertions(+), 1 deletion(-)
  

  git log -p -n
  
显示文件的详细改动
  
https://images2015.cnblogs.com/blog/213419/201609/213419-20160907083638879-315754714.png
  git log --graph
  
简单的图形显示分支情况
  
https://images2015.cnblogs.com/blog/213419/201609/213419-20160907084018848-66185039.png
  git log --pretty=format:&quot; &quot;
  控制显示的记录格式,常用的格式占位符写法及其代表的意义如下:
  选项 说明
  
%H 提交对象(commit)的完整哈希字串
  
%h 提交对象的简短哈希字串
  
%T 树对象(tree)的完整哈希字串
  
%t 树对象的简短哈希字串
  
%P 父对象(parent)的完整哈希字串
  
%p 父对象的简短哈希字串
  
%an 作者(author)的名字
  
%ae 作者的电子邮件地址
  
%ad 作者修订日期(可以用 -date= 选项定制格式)
  
%ar 作者修订日期,按多久以前的方式显示
  
%cn 提交者(committer)的名字
  
%ce 提交者的电子邮件地址
  
%cd 提交日期
  
%cr 提交日期,按多久以前的方式显示
  
%s 提交说明
  
如下操作:
  

$ git log --pretty=format:&quot;%h -%an,%ar : %s&quot; -3  
d0b9a20 -BeginMan,24 hours ago : ok
  
8c186cd -BeginMan,24 hours ago : mi
  
b2a3100 -BeginMan,24 hours ago : what?
  

  显示了前3条的信息,简单的哈希值,作者,提交时间,提交说明。
  个人感觉这个命令挺好的,为了方面使用,还是做个别名吧:
  

$ git config alias.logs &quot;log --pretty=format:'%h -%an,%ar:%s'&quot;  
$ git config alias.logs
  
log --pretty=format:'%h -%an,%ar:%s'
  
$ git logs
  

  git log --pretty=oneline
  
一行显示,只显示哈希值和提交说明。
  git log --pretty=oneline
  
显示指定path(目录或文件)下的提交
  
https://images2015.cnblogs.com/blog/213419/201609/213419-20160907084619254-1561285202.png
  指定日期、关键字、作者
  如两天前的提交历史:git log --since=2.days
  如指定作者为&quot;BeginMan&quot;的所有提交:$ git log --author=&quot;xxxx&quot;
  如指定关键字为“init”的所有提交:$ git log --grep=init
  如指定提交者为&quot;Jack&quot;的所有提交:$ git log --committer=Jack
  注意作者与提交者的关系:作者是程序的修改者,提交者是代码提交人。
  如指定2天前,作者为“BeginMan”的提交含有关键字'init'的前2条记录:$ git log --since=2.days --author=BeginMan --grep=init -2
  
上面选项后面的参数可以带单双引号
  使用说明如下:
  选项 说明
  -(n) 仅显示最近的 n 条提交
  --since, --after 仅显示指定时间之后的提交。
  --until, --before 仅显示指定时间之前的提交。
  --author 仅显示指定作者相关的提交。
  --committer 仅显示指定提交者相关的提交。
  git log 命令支持的选项
  -p 按补丁格式显示每个更新之间的差异。
  --stat 显示每次更新的文件修改统计信息。
  --shortstat 只显示 --stat 中最后的行数修改添加移除统计。
  --name-only 仅在提交信息后显示已修改的文件清单。
  --name-status 显示新增、修改、删除的文件清单。
  --abbrev-commit 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符。
  --relative-date 使用较短的相对时间显示(比如,“2 weeks ago”)。
  --graph 显示 ASCII 图形表示的分支合并历史。
  --pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format(后跟指定格式)。
  显示帮助
  

git log --help  

  参考:http://www.cnblogs.com/BeginMan/p/3577553.html
页: [1]
查看完整版本: git查看日志