实用的git log用法

git log可以很方便地查看日志,可以根据自己需要,将日志按照特定格式显示,或者输出某种格式。
最原始的输出样式:

$ git log

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sat Mar 15 16:40:33 2008 -0700

    removed unnecessary test

commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sat Mar 15 10:31:28 2008 -0700

    first commit

这时输出的是最近几个git log,每个log都非常详细,如果想要简洁的显示模式,可以试试下面的:
(先按q键退出 git log)

git log –pretty=online

将log导出,可以用在代码后面加上 >filename.txt,或者其他格式,例如:

git log –pretty=online >log.xml

显示最近两个git文件的差异变化

git log -p -2

-2表示最近两个文件

git log –stat

查看最近提交的状态

git log 按照特定格式输出,例如:

git log –pretty=format:”%h - %an, %ar : %s”

ca82a6d - Scott Chacon, 6 years ago : changed the version number
085bb3b - Scott Chacon, 6 years ago : removed unnecessary test
a11bef0 - Scott Chacon, 6 years ago : first commit

自定义格式:
%H - Commit hash
%h - Abbreviated commit hash
%T - Tree hash
%t - Abbreviated tree hash
%P - Parent hashes
%p - Abbreviated parent hashes
%an - Author name
%ae - Author email
%ad - Author date (format respects the –date=option)
%ar - Author date, relative
%cn - Committer name
%ce - Committer email
%cd - Committer date
%cr - Committer date, relative
%s - Subject

其他git log格式可以参考:
https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值