[译]git log

git log

git log命令用来显示提交的快照. 能列出来你项目的历史, 能过滤和搜索你指定的一些修改. git status能让你检查工作目录和stage区的状态, git log只提供被commited到head的一些历史信息.

用法

git log

使用默认格式展示这个项目的commit历史. 如果输出超过一屏, 可以使用空格键来展示下一屏, 或者按q推出.

git log -n <limit>

限制只展示最近<limit>条commit历史.   如果<limit>为3那么只显示最近的3次commit历史.

  

git log --online

压缩每个commit到一行. 

git log --stat

输出包括了git log的信息, 并且额外显示了哪些文件被修改了, 哪一行是新加的或者被删除了.

git log -p

有点类似于git log --state, 但是git log -p提供的信息更加详细, 他把修改的内容也给展现出来了.

git log --author="<pattern>"

搜索指定作者的commit. <pattern>可以是正则表达式.

git log --grep="<pattern>"

搜索commit描述匹配<pattern>的commit. <pattern>同样可以是正则表达式.

git log <since>..<until>

显示<since>到<until>之间的commit. <since>和<until>这两个参数可以是commit ID, branch名字, HEAD.

git log <file>

只显示指定文件的commit.

git log --graph --decorate -- online

这个非常用用. --graph会在最左边输出一个基于文本的符号(为了好看, 或者分类).

--decorate会把branch的名字和tag的名字也显示出来.

--online会把每个commit信息压缩成一行.

讨论

commit 3157ee3718e180a9476bf2e5cab8e3f1e78a73b7
Author: John Smith

第一行commit后面的40个字符是代表这一次commit的SHA-1校验码, 他是唯一的. 这个校验码有两个用途. 第一, 确保commit的完整--如果他被污染了, commit会生成一个不同的校验码. 第二, 作为commmit的一个唯一的ID号.

这个ID能在一些命令中使用, 例如git log <since>..<untile>(git log 3157e..5ab91). 

~符号用来表示一个相对于某个commit之前的相对位置的commit. 例如, 3157e~1表示在3157e之前的一个commit, HEAD~3表示当前commit之前的第三个commit.

例子

option可以组合使用.

git log --author="John Smith" -p hello.py

完整显示John Smith对hello.py这个文件所做的修改.

..符号可用于比较branch. 下面的例子展示了some-feature中有但是master中没有的commit

git log --oneline master..some-feature

  

原文地址:https://www.cnblogs.com/irocker/p/git-log.html