git 如何通过哈希显示提交的日期和时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50452866/
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 show date and time of a commit by hash
提问by Mike Eng
I used git reflog
to identify a hash for when I created a particular branch. I got the hash of fe1ddcdef
. I haven't pushed this branch to the remote yet. I'm now trying to find the date and time for when fe1ddcdef
took place. git reflog
only shows me:
我曾经git reflog
在创建特定分支时识别哈希。我得到了fe1ddcdef
. 我还没有把这个分支推送到远程。我现在试图找到发生的日期和时间fe1ddcdef
。git reflog
只显示我:
fe1ddcdef HEAD@{11}: checkout: moving from master to handoff
fe1ddcdef HEAD@{11}: checkout: moving from master to handoff
which does not have a date or time.
没有日期或时间。
git log
is far too verbose, since it contains commits from all of my colleagues and I can't easily find the needle of fe1ddcdef
in that haystack.
git log
太冗长了,因为它包含我所有同事的提交,我无法轻易在大海捞针中找到针头fe1ddcdef
。
How can I simply find the date and time of commit fe1ddcdef
?
我怎样才能简单地找到提交的日期和时间fe1ddcdef
?
回答by Obsidian
Simply use :
只需使用:
git show fe1ddcdef
… to display the content of the commit. Actually, once you have any expression that identifies a commit object, you can use it in all places that require a revision. These expressions can be an hexadecimal hash (even partial), a branch name or a tag name. It can also be one of these, associated to one or many operators such as "^", or "~", or "@".
... 显示提交的内容。实际上,一旦您有了标识提交对象的任何表达式,您就可以在所有需要修改的地方使用它。这些表达式可以是十六进制散列(甚至部分)、分支名称或标记名称。它也可以是其中之一,与一个或多个运算符相关联,例如“^”、“~”或“@”。
This means that you can also use git log fe1ddcdef
to get the full history of the branch starting from this point.
这意味着您还可以使用git log fe1ddcdef
从这一点开始获取分支的完整历史记录。
If you want to get only date and time of it and nothing else, you can type :
如果您只想获取它的日期和时间而不是其他任何内容,您可以输入:
git show --no-patch --no-notes --pretty='%cd' fe1ddcdef
Replace '%cd'
by '%h %cd %s'
to add hash summary and commit's subject message.
更换'%cd'
通过'%h %cd %s'
添加散列摘要和提交的主题消息。
回答by UsamaAmjad
You can try
你可以试试
git reflog --date=iso
You can also make your own formats using git pretty formats. Also look at this answerfor more options.
回答by torek
I'm now trying to find the date and time for when
fe1ddcdef
took place
现在我试图找到的日期和时间
fe1ddcdef
发生
"Took place" is not well defined, but I can note that every commit has two date-and-time stamps associated with it: the author dateand the commit date.
“已发生”没有明确定义,但我可以注意到每个提交都有两个与之相关的日期和时间戳:作者日期和提交日期。
Typically these two are the same, unless you use any of the various options that copy commits, in which case the author timestamp is the date it was first committed and the committer timestamp is when that particular commit was made.
通常这两个是相同的,除非您使用复制提交的各种选项中的任何一个,在这种情况下,作者时间戳是第一次提交的日期,提交者时间戳是进行特定提交的时间。
Both timestamps are under the complete control of the user. Typically people don't override them, though, so that they're as accurate as their own computer's clock (i.e., not very).
两个时间戳都在用户的完全控制之下。但是,通常人们不会覆盖它们,因此它们与自己计算机的时钟一样准确(即,不是很准确)。
To see both dates, use, e.g.:
要查看两个日期,请使用,例如:
git log --no-walk --pretty=fuller fe1ddcdef
To see just one, you can leave out the format, or use git show <hash>
(which also shows a diff). To get justthe date or dates, use --pretty=format:<directives>
or --format=<directives>
. The directives that print the author date have the form %a<letter>
and those that print the committer date have the form %c<letter>
, where the <letter>
part is one of d
, D
, r
, t
, i
, or I
. For more details see the PRETTY FORMATS section of the git log
documentation.
要仅查看一个,您可以省略格式,或使用git show <hash>
(也显示差异)。要仅获取一个或多个日期,请使用--pretty=format:<directives>
或--format=<directives>
。打印作者日期的指令有格式,打印提交者日期的指令%a<letter>
有格式%c<letter>
,其中<letter>
部分是d
, D
, r
, t
, i
, 或 之一I
。有关更多详细信息,请参阅文档的PRETTY FORMATS 部分git log
。
回答by VonC
The normalized way to reference a commit is abbreviated hash (subject, date)
, without the time. It is called a "reference".
引用提交的规范化方法是abbreviated hash (subject, date)
,没有时间。它被称为“参考”。
With Git 2.25 (Q1 2020), "git log
" family learned "--pretty=reference
" that gives the name of a commit in the format that is often used to refer to it in log messages.
在 Git 2.25(2020 年第 1 季度)中,“git log
家庭学习”--pretty=reference
以通常用于在日志消息中引用它的格式给出提交的名称。
And that format is close to what you are looking for.
这种格式与您要查找的格式很接近。
See commit 3798149, commit 1f0fc1d, commit 618a855, commit ac52d94, commit 3e8ed3b, commit 4982516, commit f0f9de2, commit fb2ffa7, commit bae74c9, commit bd00717(20 Nov 2019) by Denton Liu (Denton-L
).
See commit 0df6211(20 Nov 2019) by René Scharfe (rscharfe
).
(Merged by Junio C Hamano -- gitster
--in commit d37cfe3, 10 Dec 2019)
见犯3798149,提交1f0fc1d,提交618a855,提交ac52d94,提交3e8ed3b,提交4982516,提交f0f9de2,提交fb2ffa7,提交bae74c9,提交bd00717(二〇一九年十一月二十〇日)由丹顿刘(Denton-L
)。
请参阅René Scharfe ( ) 的commit 0df6211(20 Nov 2019 )。(由Junio C Hamano合并-- --在d37cfe3 提交中,2019 年 12 月 10 日)rscharfe
gitster
pretty
: provide short date formatSigned-off-by: René Scharfe
Signed-off-by: Denton LiuAdd the placeholders
%as
and%cs
to format author date and committer date, respectively, without the time part, like--date=short
does, i.e. likeYYYY-MM-DD
.
pretty
: 提供短日期格式签字人:René Scharfe
签字人:Denton Liu添加占位符
%as
和%cs
分别格式化作者日期和提交者日期,没有时间部分,就像--date=short
do,即 likeYYYY-MM-DD
。
Why?
Because of contribution and patch:
为什么?
由于贡献和补丁:
pretty
: implement 'reference
' formatBased-on-a-patch-by: SZEDER Gábor
Signed-off-by: Denton LiuThe standard format for referencing other commits within some projects(such as git.git) is the
reference
format.
This is described inDocumentation/SubmittingPatches
as:If you want to reference a previous commit in the history of a stable branch, use the format "abbreviated hash (subject, date)", like this:
.... Commit f86a374 (pack-bitmap.c: fix a memleak, 2015-03-30) noticed that ... ....
Since this format is so commonly used, standardize it as a pretty format.
pretty
: 实现 'reference
' 格式基于补丁:SZEDER Gábor
签字人:Denton Liu在某些项目(例如git.git)中引用其他提交的标准格式是
reference
format。
这被描述Documentation/SubmittingPatches
为:如果要引用稳定分支历史记录中的先前提交,请使用“缩写哈希(主题,日期)”格式,如下所示:
.... Commit f86a374 (pack-bitmap.c: fix a memleak, 2015-03-30) noticed that ... ....
由于这种格式非常常用,请将其标准化为一种漂亮的格式。
The pretty-formats
documentation now includes:
'
reference
'<abbrev hash> (<title line>, <short author date>)
This format is used to refer to another commit in a commit message and is the same as
--pretty='format:%C(auto)%h (%s, %ad)'
.
By default, the date is formatted with--date=short
unless another--date
option is explicitly specified.
As with anyformat:
with format placeholders, its output is not affected by other options like--decorate
and--walk-reflogs
.
'
reference
'<abbrev hash> (<title line>, <short author date>)
此格式用于引用提交消息中的另一个提交,与
--pretty='format:%C(auto)%h (%s, %ad)'
.
默认情况下,--date=short
除非--date
明确指定另一个选项,否则日期格式为。
与任何format:
格式占位符一样,其输出不受其他选项(如--decorate
和 )的影响--walk-reflogs
。
Before Git 2.25, as shown in WisdmLabs's answer, you might do:
在 Git 2.25 之前,如WisdmLabs的回答所示,您可能会这样做:
git show -s --date=short --pretty='format:%h (%s, %ad)' <commit>
Now (Git 2.25+):
现在(Git 2.25+):
git show -s --pretty=reference <commit>