[英]Why does "git cat-file -p HEAD^2" fail?
"git cat-file -p HEAD^2" gives me the following error: “git cat-file -p HEAD^2”给了我以下错误:
fatal: Not a valid object name HEAD^2
However, using the "~" format, it works:但是,使用“〜”格式,它可以工作:
$ git cat-file -p HEAD~2
gitrevision man page says the following: gitrevision 手册页说明如下:
... A suffix ^ to a revision parameter means the first parent of that commit object.
... 修订版参数的后缀 ^ 表示该提交对象的第一个父级。 rev^n means the nth parent (ie rev^ is equivalent to rev^1)
rev^n 表示第 n 个父级(即 rev^ 相当于 rev^1)
What have I misunderstood?我误解了什么?
You have a similar error message on Windows (in a CMD session, not in a git-bash session).您在 Windows 上有类似的错误消息(在 CMD 会话中,而不是在 git-bash 会话中)。
You need to escape the ^
, with an ^
.您需要使用
^
转义^
。
git cat-file -p HEAD^^2
But that won't work unless HEAD has two parents (meaning is the result of a merge), which seems to be the case here.但这不会起作用,除非 HEAD 有两个父级(意思是合并的结果),这里似乎就是这种情况。
For instance:例如:
C:\Users\vonc\prog\git\git>gl
* 74a844a - (HEAD -> master) Merge branch 'rj/mailmap-ramsay' (6 days ago) <Junio C Hamano>
|\
| * dafc047 - mailmap: update my entry with new email address (11 days ago) <Ramsay Jones>
* | b6bd2d0 - Merge branch 'bn/send-email-smtp-auth-error-message-fix' (6 days ago) <Junio C Hamano>
That gives:这给出了:
C:\Users\vonc\prog\git\git>git cat-file -p @^2
fatal: Not a valid object name @2
C:\Users\vonc\prog\git\git>git cat-file -p @^^2
tree c78343c7a98b4cb8a455d73aeecaa8acfa2cb30e
parent f4d9753a89bf04011c00e943d85211906e86a0f6
author Ramsay Jones <ramsay@ramsayjones.plus.com> 1441122606 +0100
committer Junio C Hamano <gitster@pobox.com> 1442419728 -0700
Since your error message is Not a valid object name HEAD^2
, instead of Not a valid object name @2
, that means the HEAD has only one parent.由于您的错误消息是
Not a valid object name HEAD^2
,而不是Not a valid object name @2
,这意味着 HEAD 只有一个父级。
HEAD~2" works for me. Isn't "HEAD^n" equivalent to "HEAD~n"?
HEAD~2”对我有用。“HEAD^n”不等于“HEAD~n”吗?
No:不:
HEAD~
andHEAD^
are equivalent.HEAD~
和HEAD^
是等价的。
The difference becomes apparent when you specify a number.当您指定一个数字时,差异就会变得明显。
HEAD~2
means “the first parent of the first parent,” or “the grandparent”HEAD~2
意思是“第一个父母的第一个父母”或“祖父母”
X--x--x
/
Y
@~2
is X
, while @^2
is Y
. @~2
是X
,而@^2
是Y
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.