我试图在Git中显示最后一次提交,但我需要一个特殊格式的日期.
我知道日志漂亮格式%ad尊重--date格式,但--date我能找到的唯一格式是"短".我想知道其他人,以及我是否可以创建一个自定义的,例如:
git -n 1 --date=**YYMMDDHHmm** --pretty=format:"Last committed item in this release was by %%an, %%aD, message: %%s(%%h)[%%d]"
Run Code Online (Sandbox Code Playgroud) 最近,我分叉了一个由github托管的存储库,贡献者遍布全世界,并发现每个提交日志都包含提交者的时区信息.
2013-11-07 02:31:41 +0545 <-- This committer is living in Nepal. Surely.
2013-11-04 12:58:36 -0600 <-- This committer is living in CST or Ecuador or Chili or ...
2013-10-31 10:36:36 +0700 <-- This committer is living in Indonesia or Thai or Mongolia or Laos or Australia or ...
:
Run Code Online (Sandbox Code Playgroud)
我知道可以通过编辑输出格式(例如git:timezone和timestamp格式)来隐藏它,但是这隐藏了github存储库中实际保存的内容,仅限于我的眼睛.每个提交者的时区肯定都保存在github的服务器中.
所以我的问题:
随着--date=local git log我的(用户)的时区显示日期:
$ git log --date=local -3 --pretty=tformat:'%cd %h' --abbrev-commit
Thu Dec 18 15:22:11 2014 dc20f74
Thu Dec 18 14:01:26 2014 06c214f
Tue Nov 4 03:48:44 2014 ac33158
Run Code Online (Sandbox Code Playgroud)
该手册页说
- date [...]仅对以人类可读格式显示的日期生效,例如使用--pretty时.
但是使用ISO格式%ci它不会生效,事实上--date=local和--date=default产品完全相同的输出:
$ git log --date=local -3 --pretty=tformat:'%ci %h' --abbrev-commit
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f
2014-11-04 17:18:44 +0530 ac33158
$ git log --date=default -3 --pretty=tformat:'%ci %h' --abbrev-commit
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f …Run Code Online (Sandbox Code Playgroud)