git:“branchname”和“refs/heads/branchname”之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1526471/
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
git: difference between "branchname" and "refs/heads/branchname"
提问by Albert
Best to be explained at an example: I am on branch 0.58 of repository and this his how I pull:
最好用一个例子来解释:我在存储库的 0.58 分支上,这是我拉的方式:
git pull origin 0.58
When I just call "git pull", I get:
当我只是调用“git pull”时,我得到:
ip238:openlierox az$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.0.58.merge' in
your configuration file does not tell me either. Please
name which branch you want to merge on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details on the refspec.
If you often merge with the same branch, you may want to
configure the following variables in your configuration
file:
branch.0.58.remote = <nickname>
branch.0.58.merge = <remote-ref>
remote.<nickname>.url = <url>
remote.<nickname>.fetch = <refspec>
See git-config(1) for details.
Seems I probably forgot some option (--track ?) when I checked that branch out. Anyway, I have set this now:
当我检查该分支时,似乎我可能忘记了一些选项(--track ?)。无论如何,我现在已经设置了:
git config branch.0.58.merge 0.58
git config branch.0.58.remote origin
And this seems to work. Then, just because of interest, I took a look at some other branch about these setting:
这似乎有效。然后,出于兴趣,我查看了有关这些设置的其他一些分支:
ip238:openlierox az$ git config branch.0.57.merge
refs/heads/0.57
ip238:openlierox az$ git config branch.0.57.remote
origin
I was wondering now, is there a difference between "0.58" or should I specify "refs/heads/0.58"?
我现在想知道,“0.58”之间有区别还是应该指定“refs/heads/0.58”?
What is the difference exactly?
究竟有什么区别?
回答by Cascabel
A ref is anything pointing to a commit, for example, branches (heads), tags, and remote branches. You should see heads, remotes, and tags in your .git/refs directory, assuming you have all three types of refs in your repository.
ref 是指向提交的任何东西,例如,分支(头)、标签和远程分支。您应该在 .git/refs 目录中看到 head、remotes 和 tags,假设您的存储库中有所有三种类型的 refs。
refs/heads/0.58 specifies a branchnamed 0.58. If you don't specify what namespace the ref is in, git will look in the default ones. This makes using only 0.58 conceivably ambiguous - you could have both a branch and a tag named 0.58.
refs/heads/0.58 指定了一个名为 0.58的分支。如果您没有指定 ref 所在的命名空间,git 将查找默认命名空间。这使得仅使用 0.58 可能会产生歧义——您可以同时拥有一个名为 0.58 的分支和一个标签。
回答by Artem Dolobanko
Just for somebody who is curious - git show-ref
, which is available since Git v1.8.2.2, will show you all references you have in your local repository.
仅供好奇的人使用 - git show-ref
,自 Git v1.8.2.2 起可用,将显示您在本地存储库中的所有引用。
回答by Number945
See, branchName
needs to be fully resolved before GIT can actually identify it. The fully resolved name will be refs/heads/branchName
.
看,branchName
需要彻底解决,GIT 才能真正识别出来。完全解析的名称将为refs/heads/branchName
.
One of the famous commandsgit checkout branchName
actually automatically resolves it fully to identify where you want to checkout. Note that it does it automatically hence we never write it fully on our own.
著名的命令之一git checkout branchName
实际上会自动完全解析它以识别您想要结帐的位置。请注意,它会自动执行,因此我们永远不会完全自己编写。
How does it do that ? Let us look here
它是如何做到的?让我们看看这里
refname:, e.g.
master
,heads/master
,refs/heads/master
A symbolic ref name. E.g. master typically means the commit object referenced by
refs/heads/master
. If you happen to have bothheads/master
andtags/master
, you can explicitly sayheads/master
to tell Git which one you mean. When ambiguous, a<refname>
is disambiguated by taking the first match in the following rules:1.If
$GIT_DIR/<refname>
exists, that is what you mean (this is usually useful only forHEAD
,FETCH_HEAD
,ORIG_HEAD
,MERGE_HEAD
andCHERRY_PICK_HEAD
);2.otherwise,
refs/<refname>
if it exists;3.otherwise,
refs/tags/<refname>
if it exists;4.otherwise,
refs/heads/<refname>
if it exists;5.otherwise,
refs/remotes/<refname>
if it exists;6.otherwise,
refs/remotes/<refname>/HEAD
if it exists.
refname:例如
master
,heads/master
,refs/heads/master
符号引用名称。例如, master 通常表示由
refs/heads/master
. 如果您碰巧同时拥有heads/master
和tags/master
,您可以明确heads/master
告诉 Git 您指的是哪一个。当有歧义时, a<refname>
通过在以下规则中取第一个匹配项来消除歧义:1.如果
$GIT_DIR/<refname>
存在,那就是你的意思(这通常只对HEAD
,FETCH_HEAD
,ORIG_HEAD
,MERGE_HEAD
和 有用CHERRY_PICK_HEAD
);2.否则,
refs/<refname>
如果存在;3.否则,
refs/tags/<refname>
如果存在;4.否则,
refs/heads/<refname>
如果存在;5.否则,
refs/remotes/<refname>
如果存在;6.否则,
refs/remotes/<refname>/HEAD
如果它存在。
So by above 6 steps , it tries to resolve what is this branchName
. Hence we never need to give a fully resolved branchName to it.
所以通过以上 6 个步骤,它试图解决这是什么branchName
。因此我们永远不需要给它一个完全解析的 branchName 。
Also, go in your .git
directory and see inside the ref
folder.
另外,进入您的.git
目录并查看ref
文件夹内部。