git:“branchname”和“refs / head / branchname”之间的区别

时间:2009-10-06 15:47:49

标签: git

最好在一个例子中解释:我在存储库的分支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”?

究竟有什么区别?

3 个答案:

答案 0 :(得分:88)

ref是指向提交的任何内容,例如,分支(头),标记和远程分支。您应该在.git / refs目录中看到head,remotes和tags,假设您的存储库中有所有三种类型的ref。

refs / heads / 0.58指定名为0.58的分支。如果你没有指定ref所在的命名空间,git将查看默认的命名空间。这使得只使用0.58可以设想不明确 - 你可以同时拥有一个分支和一个名为0.58的标签。

答案 1 :(得分:29)

只是对于那些好奇的人 - git show-ref,自Git v1.8.2.2开始提供,它将显示你在本地存储库中的所有引用。

答案 2 :(得分:8)

请参阅,branchName需要在GIT实际识别之前完全解决。完全解析的名称将为refs/heads/branchName

其中一个着名的命令git checkout branchName实际上会自动完全解析它以确定您要结帐的位置。请注意,它会自动执行,因此我们永远不会完全自己编写它。

它是如何做到的? 让我们看一下here

  

refname :,例如masterheads/masterrefs/heads/master

     

符号引用名称。例如。 master通常表示提交对象   由refs/heads/master引用。如果碰巧两者都有   heads/mastertags/master,您可以明确说明heads/master   告诉Git你的意思。当含糊不清时,<refname>是。{1}}   通过以下规则中的第一场比赛消除歧义:

     

1.如果$GIT_DIR/<refname>存在,那就是您的意思(这通常仅适用于HEADFETCH_HEADORIG_HEADMERGE_HEAD和   CHERRY_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。

同时查看herehere

此外,请转到.git目录,然后查看ref文件夹。

相关问题