如何更改git日志日期格式 [英] How to change git log date formats
问题描述
我试图在git中显示最后一个提交,但我需要一个特殊格式的日期。
我知道日志格式%ad
尊重 - date
格式,但我可以找到的唯一
- date
格式是短。我想知道其他人,是否可以创建一个自定义的,如:
git -n 1 --date = ** YYMMDDHHmm ** --pretty = format:此发布中的最后提交项目是由%% an,%% aD,消息:%% s(%% h)[%% d]
其他是(从 git help log
):
- date =(relative | local | default | iso | rfc | short | raw)
仅对以人类可读格式显示的日期生效,例如使用--pretty时生效。 log.date配置变量
为日志命令的--date选项设置默认值。
--date = relative显示相对于当前时间的日期,例如2小时前。
--date = local在用户的本地时区显示时间戳。
--date = iso(或--date = iso8601)显示ISO 8601格式的时间戳。
--date = rfc(或--date = rfc2822)显示RFC 2822格式的时间戳,
经常在电子邮件中找到。
--date = short仅显示日期而不是时间,格式为YYYY-MM-DD。
--date = raw显示内部原始git格式%s%z格式的日期。
--date = default显示原始时区
(提交者或作者的)中的时间戳。
我没有内置的方法来创建自定义格式,一些shell魔法。
timestamp =`git log -n1 --format =%at`
my_date = `perl -e'print scalar localtime($ timestamp)`
git log -n1 --pretty = format:Blah-blah $ my_date
这里的第一步给你一个毫秒的时间戳。您可以更改第二行以设置所需的时间戳格式。此示例为您提供类似于 - date = local
的填充日期。
I am trying to display the last commit within git, but I need the date in a special format.
I know that the log pretty format %ad
respects the --date
format, but the only --date
format I can find is "short". I want to know the others, and whether I can create a custom one such as:
git -n 1 --date=**YYMMDDHHmm** --pretty=format:"Last committed item in this release was by %%an, %%aD, message: %%s(%%h)[%%d]"
The others are (from git help log
):
--date=(relative|local|default|iso|rfc|short|raw)
Only takes effect for dates shown in human-readable format,
such as when using "--pretty". log.date config variable
sets a default value for log command’s --date option.
--date=relative shows dates relative to the current time, e.g. "2 hours ago".
--date=local shows timestamps in user’s local timezone.
--date=iso (or --date=iso8601) shows timestamps in ISO 8601 format.
--date=rfc (or --date=rfc2822) shows timestamps in RFC 2822 format,
often found in E-mail messages.
--date=short shows only date but not time, in YYYY-MM-DD format.
--date=raw shows the date in the internal raw git format %s %z format.
--date=default shows timestamps in the original timezone
(either committer’s or author’s).
There is no built-in way that I know of to create a custom format, but you can do some shell magic.
timestamp=`git log -n1 --format="%at"`
my_date=`perl -e "print scalar localtime ($timestamp)"`
git log -n1 --pretty=format:"Blah-blah $my_date"
The first step here gets you a millisecond timestamp. You can change the second line to format that timestamp however you want. This example gives you something similar to --date=local
, with a padded day.
这篇关于如何更改git日志日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!