问题描述
我注意到有2个HEAD:
I noticed there are 2 HEADs:
- .git \ HEAD
- .git \ refs \ remotes \ origin \ HEAD
当我使用git show-ref HEAD
时,它只会给我以下信息:
When I use git show-ref HEAD
, it only gives me this:
ce0762c073b407d794f54f0b5d2a50375fdcb609 refs/remotes/origin/HEAD
当我使用git rev-parse HEAD
时,它为我提供了.git \ HEAD的值:
Whle when I use git rev-parse HEAD
, it gives me the value of .git\HEAD:
a758e523fe40e799194878bac567b7f4b8eec2b9
为什么Git使用2个不同的命令来显示HEAD?有什么强烈的理由吗?
Why Git use 2 different commands to show HEAD? Any strong reason?
推荐答案
git-show-ref
显示存储库中的引用及其提交ID的列表.它可能应该称为git-show-refs
.优先于直接引用.git
目录中的文件.
git-show-ref
shows a list of references in your repository and their commit IDs. It should probably be called git-show-refs
. It's preferred over directly referencing files in the .git
directory.
当您说git show-ref HEAD
时,您并不需要输入HEAD
.您要查找的是列表中与模式HEAD
匹配的所有引用. HEAD
本身通常会被过滤掉,所以您会得到refs/remotes/origin/HEAD
.您可以在--head
中包含HEAD
.
When you say git show-ref HEAD
you're not asking for HEAD
. What you're asking for is any references in the list which match the pattern HEAD
. HEAD
itself is normally filtered out, so you get refs/remotes/origin/HEAD
. You can include HEAD
with --head
.
$ git show-ref --head HEAD
f37beeea95f3b0e6b064f6d4b5f835a058e0568c HEAD
aa1124b89f38eed793e2b9f2d2b2ba5d80a27a20 refs/remotes/origin/HEAD
因此,您不应该使用git show-ref <ref>
来查找引用.
So you shouldn't be using git show-ref <ref>
to look up references.
git-rev-parse
带有修订参数并返回提交ID .它的意思是要处理可以引用提交的多种不同方式.例如...
git-rev-parse
takes a revision parameter and gives back a commit ID. Its meant to deal with the myriad different ways you can refer to a commit. For example...
$ git rev-parse --verify master
aa1124b89f38eed793e2b9f2d2b2ba5d80a27a20
$ git rev-parse --verify heads/master
aa1124b89f38eed793e2b9f2d2b2ba5d80a27a20
$ git rev-parse --verify refs/heads/master
aa1124b89f38eed793e2b9f2d2b2ba5d80a27a20
git rev-parse --verify <ref>
是查找引用的提交ID所应使用的.
git rev-parse --verify <ref>
is what you should be using to look up the commit ID of a reference.
这篇关于为什么git使用2个不同的命令显示HEAD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!