有没有办法让 git-reflog 在每个条目旁边显示一个日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17369254/
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
Is there a way to cause git-reflog to show a date alongside each entry?
提问by Andrew Ferrier
The git-reflog command doesn't by default show a date alongside each entry, which strikes me as a strange oversight; I think this would be very helpful.
默认情况下,git-reflog 命令不会在每个条目旁边显示日期,这让我觉得是一个奇怪的疏忽;我认为这会非常有帮助。
Are there any command-line options, or other tweaks, which can be employed to cause it to show when each reflog entry was added? The manpageisn't forthcoming...
是否有任何命令行选项或其他调整,可用于使其在添加每个 reflog 条目时显示?该手册页没有着落......
回答by Balog Pal
As the man page writes you can use the options for git log
, say git reflog --pretty=short
or any other as you like
正如手册页所写,您可以根据需要使用git log
、 saygit reflog --pretty=short
或任何其他选项
try
尝试
git reflog --date=iso
回答by Klas Mellbourn
You can use the --walk-reflogs
variant of git log
:
您可以使用以下--walk-reflogs
变体git log
:
git log -g
This is rather verbose by default, and prints the date among other things. You can format it with the standard --pretty=
flag.
默认情况下,这是相当冗长的,并打印日期等。您可以使用标准--pretty=
标志对其进行格式化。
You can also use the reflog command directly with the --pretty=
flag to format the output.
您还可以直接使用带有--pretty=
标志的 reflog 命令来格式化输出。
git reflog --pretty='%cd %h %gd %gs'
In the format above, %cd
shows the commit date to the left of the normal reflog output.
在上面的格式中,%cd
在正常 reflog 输出的左侧显示提交日期。
回答by blueyed
You have to use a custom format:
您必须使用自定义格式:
git reflog --format='%C(auto)%h %<|(20)%gd %C(blue)%cr%C(reset) %gs (%s)'
In the above format, %h
is the commit hash, %cr
is the relative committer date, %gs
is the reflog subject, and, %s
is the commit subject. Look at the git-log docsfor other possible placeholders. For instance, using %ci
instead of %cr
will show absolute commit dates.
在上面的格式中,%h
是提交哈希,%cr
是相对提交者日期,%gs
是引用日志主题,%s
是提交主题。查看git-log 文档以了解其他可能的占位符。例如,使用%ci
代替%cr
将显示绝对提交日期。
You can save this in your ~/.gitconfig using a custom pretty
format and refer to it via an alias:
您可以使用自定义pretty
格式将其保存在您的 ~/.gitconfig 中,并通过别名引用它:
[alias]
rl = reflog --pretty=reflog
[pretty]
reflog = %C(auto)%h %<|(20)%gd %C(blue)%cr%C(reset) %gs (%s)
回答by gitster
Tell git
in what format, either counted reflog
entries or timed reflog
entries, i.e.
告诉git
以什么格式,计数reflog
条目或定时reflog
条目,即
$ git reflog @{now}
$ git reflog @{0}
回答by VonC
Note git 2.10 (Q3 2016) improves the documentation about date with git reflog
.
注意 git 2.10(2016 年第三季度)改进了关于日期的文档git reflog
。
See commit 642833d, commit 1a2a1e8(27 Jul 2016), and commit d38c7b2, commit 522259d, commit 83c9f95, commit 2b68222(22 Jul 2016) by Jeff King (peff
).
Helped-by: Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
--in commit 0d32799, 08 Aug 2016)
请参阅Jeff King ( ) 的commit 642833d、commit 1a2a1e8(2016 年 7 月 27 日)和commit d38c7b2、commit 522259d、commit 83c9f95、commit 2b68222(2016 年 7 月 22 日)。
帮助者:杰夫·金 ( )。(由Junio C Hamano合并-- --在提交 0d32799,2016 年 8 月 8 日)peff
peff
gitster
The rev-list
options is updated:
The reflog designator in the output may be shown as
ref@{Nth}
(whereNth
is the reverse-chronological index in the reflog) or asref@{timestamp}
(with the timestamp for that entry), depending on a few rules.
输出中的 reflog 指示符可能显示为
ref@{Nth}
(其中Nth
是 reflog 中的反向时间索引)或作为ref@{timestamp}
(带有该条目的时间戳),具体取决于一些规则。
It includes:
- an update about --date=raw
:
它包括: - 关于以下内容的更新--date=raw
:
shows the date as seconds since the epoch (1970-01-01 00:00:00 UTC), followed by a space, and then the timezone as an offset from UTC (a
+
or-
with four digits; the first two are hours, and the second two are minutes).
I.e., as if the timestamp were formatted withstrftime("%s %z")
).
Note that the-local
option does not affect theseconds-since-epoch
value (which is always measured in UTC), but does switch the accompanying timezone value.
将日期显示为自纪元以来的秒数 (1970-01-01 00:00:00 UTC),后跟一个空格,然后是时区作为与 UTC 的偏移量(a
+
或-
四位数字;前两位是小时,然后是时区)后两个是分钟)。
即,就好像时间戳用strftime("%s %z")
)格式化一样。
请注意,该-local
选项不会影响该seconds-since-epoch
值(始终以 UTC 度量),但会切换伴随的时区值。
And a new option: --date=unix
还有一个新选项: --date=unix
shows the date as a Unix epoch timestamp (seconds since 1970).
As with--raw
, this is always in UTC and therefore-local
has no effect.
将日期显示为 Unix 纪元时间戳(自 1970 年以来的秒数)。
与 一样--raw
,这始终采用 UTC,因此-local
无效。