git:“分支名称”和“引用/标题/分支名称”之间的区别


96

最好在一个例子中解释一下:我在存储库的分支0.58上,这是我的拉法:

git pull origin 0.58

当我只称“ 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.

当我检查分支时,似乎可能忘记了某些选项(--track?)。无论如何,我现在已经设置了:

git config branch.0.58.merge 0.58
git config branch.0.58.remote origin

这似乎可行。然后,仅出于兴趣,我查看了有关这些设置的其他分支:

ip238:openlierox az$ git config branch.0.57.merge
refs/heads/0.57
ip238:openlierox az$ git config branch.0.57.remote
origin

我现在想知道,“ 0.58”之间是否有区别?还是应该指定“ refs / heads / 0.58”?

到底有什么区别?


1
只是为了解决标题中的拼写错误(现在不要通过修改修改旧标题而使它混乱),它应该显示为“ refs / heads / branchname”heads并带有一个“ s”。
RomainValeri

Answers:


129

Aref是指向提交的任何内容,例如,分支(头),标签和远程分支。.git/refs假定存储库中具有所有三种引用类型,则应该在目录中看到head,remote和tag 。

refs/heads/0.58指定一个名为0.58的分支。如果不指定引用所在的名称空间,则git将查找默认名称空间。这使得仅使用0.58可能是模棱两可的-您可以同时拥有一个分支和一个名为0.58的标记。


3
非常感谢,这很好地说明了这一点。它只适用于简单的“ 0.58”,因为没有这样的命名标签。
艾伯特

1
是的,从本质上讲,它永远是完全可以的,但是安全是一件好事。
卡斯卡贝尔

这个答案是宝贵的。最后有人解释了Git,我很喜欢!谢谢。
aderchox

9
这里是所有的人都为清楚:refs/heads/refs/remotes/refs/tags/
吉姆·阿霍

40

对于git show-ref某些好奇的人- ,它从Git v1.8.2.2开始提供,它将向您显示本地存储库中的所有引用。


3
git log --decorate=full将显示在历史文献的全名
galath

19

看到,branchName需要完全解决,GIT才能真正识别它。完全解析的名称为refs/heads/branchName

git checkout branchName实际上,其中一个著名的命令会自动将其完全解析,以识别您要在哪里结帐。请注意,它会自动执行,因此我们永远不会完全自己编写它。

它是如何做到的?让我们看看这里

refname:例如masterheads/masterrefs/heads/master

符号引用名称。例如,master表示通过引用的提交对象refs/heads/master。如果您碰巧同时拥有 heads/mastertags/master,则可以明确地说出heads/master要告诉Git的意思。当模棱两可时,<refname>通过遵循以下规则中的第一个匹配项来消除a的歧义:

1.如果$GIT_DIR/<refname>存在,那就是你的意思(这通常只对有用的HEADFETCH_HEADORIG_HEADMERGE_HEADCHERRY_PICK_HEAD);

2.否则,refs/<refname>如果存在的话;

3.否则,refs/tags/<refname>如果存在的话;

4.否则,refs/heads/<refname>如果存在的话;

5.否则,refs/remotes/<refname>如果存在的话;

6.否则,refs/remotes/<refname>/HEAD如果存在。

因此,通过以上6个步骤,它尝试解决此问题branchName。因此,我们无需为其提供完全解析的branchName。

也看这里这里

此外,进入.git目录并查看ref文件夹内部。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.