git log (一)

1、我们可以用 --oneline 选项来查看历史记录的简洁的版本。

$ git log --oneline
88afe0e Merge branch 'change_site'
14b4dca 新增加一行
d7e7346 changed the site
556f0a0 removed test2.txt
2e082b7 add test2.txt
048598f add test.txt
85fc7e7 test comment from w3cschool.cc

 

2、我们还可以用 --graph 选项,查看历史中什么时候出现了分支、合并。以下为相同的命令,开启了拓扑图选项:

$ git log --oneline --graph
*   88afe0e Merge branch 'change_site'
|\  
| * d7e7346 changed the site
* | 14b4dca 新增加一行
|/  
* 556f0a0 removed test2.txt
* 2e082b7 add test2.txt
* 048598f add test.txt
* 85fc7e7 test comment from w3cschool.cc
--------------------- 
现在我们可以更清楚明了地看到何时工作分叉、又何时归并。

3、你也可以用 '--reverse'参数来逆向显示所有日志。

$ git log --reverse --oneline
85fc7e7 test comment from w3cschool.cc
048598f add test.txt
2e082b7 add test2.txt
556f0a0 removed test2.txt
d7e7346 changed the site
14b4dca 新增加一行
88afe0e Merge branch 'change_site'
 

4、如果只想查找指定用户的提交日志可以使用命令:git log --author , 例如,比方说我们要找 Git 源码中 Linus 提交的部分:

$ git log --author=Linus --oneline -5
81b50f3 Move 'builtin-*' into a 'builtin/' subdirectory
3bb7256 make "index-pack" a built-in
377d027 make "git pack-redundant" a built-in
b532581 make "git unpack-file" a built-in
112dd51 make "mktag" a built-in

 

你不需要使用整个名字

git log --author="Jon"

将匹配由“Jonathan Smith”做出的提交,

git log --author=Jon

git log --author=Smith

也会工作。如果不需要任何空格,引号是可选的。

您还可以轻松地匹配多个作者,因为正则表达式是此过滤器的基础机制。所以要列出Jonathan或Adam的提交,你可以这样做:

git log --author="\(Adam\)\|\(Jon\)"

为了排除特定作者或作者集使用正则表达式提交的提交,如in this question所示,您可以将negative lookahead与–perl-regexp开关结合使用:

 

git log --author='^(?!Adam|Jon).*$' --perl-regexp

或者,您可以使用bash和管道排除Adam撰写的提交:

 

git log --format='%H %an' |

  grep -v Adam |

  cut -d ' ' -f1 |

  xargs -n1 git log -1

如果要排除由Adam提交(但不一定是编写的)提交,请将%an替换为%cn。更多细节在我的博客文章:http://dymitruk.com/blog/2012/07/18/filtering-by-author-name/

 

5、如果你要指定日期,可以执行几个选项:--since 和 --before,但是你也可以用 --until 和 --after。

例如,如果我要看 Git 项目中三周前且在四月十八日之后的所有提交,我可以执行这个(我还用了 --no-merges 选项以隐藏合并提交):

$ git log --oneline --before={3.weeks.ago} --after={2010-04-18} --no-merges
5469e2d Git 1.7.1-rc2
d43427d Documentation/remote-helpers: Fix typos and improve language
272a36b Fixup: Second argument may be any arbitrary string
b6c8d2d Documentation/remote-helpers: Add invocation section
5ce4f4e Documentation/urls: Rewrite to accomodate transport::address
00b84e9 Documentation/remote-helpers: Rewrite description
03aa87e Documentation: Describe other situations where -z affects git diff
77bc694 rebase-interactive: silence warning when no commits rewritten
636db2c t3301: add tests to use --format="%N"
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值