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

Alb*_*ert 77 git

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

git pull origin 0.58
Run Code Online (Sandbox Code Playgroud)

当我打电话给"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.
Run Code Online (Sandbox Code Playgroud)

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

git config branch.0.58.merge 0.58
git config branch.0.58.remote origin
Run Code Online (Sandbox Code Playgroud)

这似乎有效.然后,仅仅因为感兴趣,我看了一些关于这些设置的其他分支:

ip238:openlierox az$ git config branch.0.57.merge
refs/heads/0.57
ip238:openlierox az$ git config branch.0.57.remote
origin
Run Code Online (Sandbox Code Playgroud)

我现在想知道,"0.58"之间是否存在差异,还是应该指定"refs/heads/0.58"?

有什么区别?

Cas*_*bel 102

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

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

  • 为了清楚起见,以下是全部内容:`refs / heads /`和`refs / remotes /`和`refs / tags /` (4认同)
  • 非常感谢,这很好地解释了它.它只使用简单的"0.58",因为没有这样的命名标签. (3认同)
  • 是的,基本上一切都会好起来,但安全是件好事。 (2认同)

Art*_*nko 36

只是对于一个好奇的人 - git show-ref从Git v1.8.2.2开始可用,它将向你显示你在本地存储库中的所有引用.

  • 另外`git log --decorate = full`还将显示历史记录中的引用全名 (3认同)

Bre*_*min 13

看,branchName需要在GIT实际识别它之前完全解决.完全解析的名称将是refs/heads/branchName.

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

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

refname:例如master,heads/master,refs/heads/master

一个象征性的引用名称.例如,master通常表示引用的提交对象refs/heads/master.如果你碰巧有两个 heads/mastertags/master,你可以明确地说heads/master要告诉Git的你的意思是哪一个.当含糊不清时,<refname>通过采用以下规则中的第一个匹配来消除歧义:

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

2.另外,refs/<refname>如果存在;

另外,refs/tags/<refname>如果它存在;

另外,refs/heads/<refname>如果它存在;

另外,refs/remotes/<refname>如果它存在;

6.另外,refs/remotes/<refname>/HEAD如果它存在.

所以通过以上6个步骤,它试图解决这个问题branchName.因此,我们永远不需要为它提供完全解析的branchName.

这里这里.

另外,进入您的.git目录并查看ref文件夹内部.