如何配置“git log”以显示“提交日期”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14243380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure 'git log' to show 'commit date'
提问by michael
How can I configure git log
to show commit date
instead of author date
?
如何配置git log
为显示commit date
而不是显示author date
?
回答by twalberg
There are several options to pretty printthe date. Probably the easiest is to just use one of the pre-baked --pretty
formats, like git log --pretty=fuller
- this will show both dates. If you want to see only one date, but make it the commit date, you can use git log --format=<some stuff>
. All the allowable codesfor defining the format are documented in git help log
. The commit date is one of %cd
, %cD
, %cr
, %ct
or %ci
, depending on what format you prefer it in.
有几个选项可以漂亮地打印日期。可能最简单的方法是仅使用一种预烘焙--pretty
格式,例如git log --pretty=fuller
- 这将显示两个日期。如果您只想查看一个日期,但将其设为提交日期,则可以使用git log --format=<some stuff>
. 用于定义格式的所有允许代码都记录在git help log
. 提交日期是之一%cd
,%cD
,%cr
,%ct
或者%ci
,这取决于什么格式你喜欢进去。
If it's something you want to do often, put it in an alias or write an auxiliary script to save on typing.
如果这是您想要经常做的事情,请将其放在别名中或编写辅助脚本以节省打字时间。
回答by raychi
You can use --pretty=format
and use %cr
for commit date relative.
您可以使用--pretty=format
和%cr
用于相对提交日期。
I have the following alias in my .gitconfig
我的 .gitconfig 中有以下别名
[alias]
lol = log --graph --pretty=format:"%C(yellow)%h%Creset%C(cyan)%C(bold)%d%Creset %C(cyan)(%cr)%Creset %C(green)%ce%Creset %s"
Then simply run git lol
and you'll see a nice color history with hash/date/author/comments.
然后只需运行git lol
,您将看到带有哈希/日期/作者/评论的漂亮颜色历史记录。
On Linux or similar systems, use single-quotes instead of double-quotes:
在 Linux 或类似系统上,使用单引号而不是双引号:
[alias]
lol = log --graph --pretty=format:'%C(yellow)%h%Creset%C(cyan)%C(bold)%d%Creset %C(cyan)(%cr)%Creset %C(green)%ce%Creset %s'
回答by Patrick Steil
I prefer this format, doesn't include author name and includes actual date for commit.
我更喜欢这种格式,不包括作者姓名,但包括实际提交日期。
git log --graph --pretty=format:"%C(yellow)%h%x09%Creset%C(cyan)%C(bold)%ad%Creset %C(green)%Creset %s" --date=short