使用git log查看日志

命令:git log

语法:

  • 指定分支
    git log 指定分支名 可以查看当前分支中属于指定分支下的提交记录

  • 指定文件
    git log 文件名

  • 指定方法
    git log -L :<funcname>:<file>
    注意需要创建.gitattributes文件,否则git无法识别代码文件。
    创建方法:
    在仓库的根目录下创建名为 .gitattributes 的文件,内容为 *.php diff=php
    例:git log -L:updateLotteryRecordStatus:src/app/Http/Service/Marketing/LotteryService.php

  • 指定文件行数范围
    git -L <n,m:file>
    例:git log -L 764,779:modules/Store/Models/Store.php

  • 指定时间范围
    git log --after="yesterday"
    git log --after="2014-7-1" --before="2014-7-4"
    git log --graph --pretty=oneline --abbrev-commit

  • 指定分支区间范围
    git log 分支前..分支后 显示在[分支后]不在[分支前]中的提交
    例:git log --oneline master..feature/example 显示在feature/example中而不在master中的提交

应用:查看哪些提交未推送到远端
方法1:git log origin/branch_name..HEAD
可省略为git log origin/branch_name..
方法2:git log  branch_name  ^origin/branch_name
例:git log master ^origin/master
方法3:git cherry -v

  • 树形结构图 分支合并图、一行显示、提交校验码缩略显示
    git log --graph --decorate --oneline --all 

更方便的使用方法:
使用gitk命令,即可在GUI图形界面查看。


参考:

  1. https://stackoverflow.com/questions/4781405/git-how-do-i-view-the-change-history-of-a-method-function
  2. https://stackoverflow.com/questions/4781405/git-how-do-i-view-the-change-history-of-a-method-function/33953022#33953022