[英]Does `branch.<name>.merge` represent a remote tracking branch or an upstream branch?
Does branch.<name>.merge
represent a remote tracking branch or an upstream branch? branch.<name>.merge
代表远程跟踪分支还是上游分支?
Version Control with Git says 使用Git的版本控制说
But how did Git know to merge those particular branches? 但是,Git如何知道合并这些特定分支? The answer comes from the configuration file: 答案来自配置文件:
[branch "master"] remote = origin merge = refs/heads/master
Paraphrased, this gives Git two key pieces of information: When
master
is the current, checked out branch, useorigin
as the default remote from which to fetch updates during a fetch (or pull). 解释一下,这为Git提供了两个关键信息:当master
是当前的已检出分支时,将origin
作为默认的远程,在提取(或拉取)期间从中获取更新。 Further, during the merge step of git pull, userefs/heads/master
from the remote as the default branch to merge into this, the master branch. 此外,在git pull的合并步骤中,使用远程的refs/heads/master
作为默认分支,以合并到master分支中。
The quote says "during the merge step of git pull, use refs/heads/master
from the remote as the default branch to merge into this, the master branch." 引言说:“在git pull的合并步骤中,使用远程的refs/heads/master
作为默认分支,并合并到master分支中。” It seems to me that branch.<name>.merge
represents a remote tracking branch instead of an upstream branch. 在我看来, branch.<name>.merge
代表一个远程跟踪分支,而不是上游分支。
But refs/heads/master
in merge = refs/heads/master
doesn't look like a remote tracking branch (which should look like refs/remotes/<remote>/master
), but a topic branch, so it seems only an upstream branch to me. 但是refs/heads/master
在merge = refs/heads/master
不像远程跟踪分支(其应该像refs/remotes/<remote>/master
),但一个主题分支,因此它似乎只上游分支给我。
The manpage of git config
says git config
的手册页说
branch.<name>.merge
Defines, together with branch..remote, the upstream branch for the given branch. 与branch..remote一起定义给定分支的上游分支。
It seems to say branch.<name>.merge
represents an upstream branch instead of a remote tracking branch. 似乎在说branch.<name>.merge
代表上游分支,而不是远程跟踪分支。
branch.<name>.merge
implies both a remote tracking branch and an upstream branch? branch.<name>.merge
是否可能同时包含远程跟踪分支和上游分支? I don't think it is possible, because a remote tracking branch and its corresponding upstream branch(es) can have different basenames, according to how remote.<remote>.fetch
is configured. 我认为这是不可能的,因为根据remote.<remote>.fetch
的配置方式,远程跟踪分支及其对应的上游分支可以具有不同的基名。 In short, branch.<name>.merge
contains the name of the remote branch on the remote server: it is the upstream branch. 简而言之, branch.<name>.merge
包含远程服务器上远程分支的名称:它是上游分支。
How to convince yourself this is true: 如何说服自己,这是真的:
Assuming branch origin/dev1
exists but not the local dev1
yet, run this: 假设分支origin/dev1
存在,但本地dev1
还不存在,请运行以下命令:
git checkout dev1
git branch -m dev1 dev2
These commands set up dev1
as having origin/dev1
as its upstream, then renames it as dev2
. 这些命令将dev1
设置为将origin/dev1
作为其上游,然后将其重命名为dev2
。
The results in my .git/config
is this: 我的.git/config
的结果是这样的:
[branch "dev2"]
remote = origin
merge = refs/heads/dev1
Now, refs/heads/dev1
is something that does not exist anywhere in my sandbox, only on the remote. 现在, refs/heads/dev1
是我的沙箱中不存在的任何东西,仅在远程存在。
Some further clarification of names, based on the discussion in the comments: 根据评论中的讨论,对名称进行了一些进一步的澄清:
local branch : master
or dev2
are local branches that can get updated from their upstream branch. 本地分支 : master
或dev2
是可以从其上游分支更新的本地分支。
remote-tracking branch : origin/master
or refs/remotes/origin/master
is a pointer stored locally to the state of the remote branch at the time of the last git fetch
or git pull
. 远程跟踪分支 : origin/master
或refs/remotes/origin/master
是在上一次git fetch
或git pull
本地存储到远程分支状态的指针。
upstream branch : this is the real remote branch, on the remote server itself, not something local. 上游分支 :这是真正的远程分支,位于远程服务器本身上,而不是本地服务器上。
git config remote.origin.fetch
will show you the "refspec" that maps refnames on the origin
remote to the local "remote-tracking branch" refs. git config remote.origin.fetch
将显示“ refspec”,该“ refspec”将origin
远程上的引用origin
映射到本地“远程跟踪分支”引用。
The default is 默认是
+refs/heads/*:refs/remotes/origin/*
and it says fetch all the refs on origin that start "refs/heads/" and substitute the *
'd text in the local rewrite, so refs/heads/master
the *
is master
, and that's what gets subbed in for the *
in the local ref, the "remote-tracking branch" ref 1 . 它说获取所有以“ refs / heads /”开头的原始引用,并在本地重写中替换*
'd文本,因此refs/heads/master
的*
是master
,这就是*
中的*
所在本地ref,即“远程跟踪分支” ref 1 。
The config file specifies which repository a branch's upstream came from and what the refname in that repository is. 配置文件指定分支的上游来自哪个存储库,以及该存储库中的refname是什么。 When you go to rebase or pull or merge and take the implicit upstream, Git looks at the branch name and the refspec for its source repo, usually origin
, and figures out what ref that would map to in this repository. 当您去变基,拉动或合并并采用隐式上游时,Git会查看分支名称和其源存储库(通常是origin
的refspec,并弄清楚该存储库中将映射到哪个ref。
So 所以
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "origin"]
url = git://github.com/git/git
fetch = +refs/heads/*:refs/remotes/origin/*
the local branch master
tracks origin
's branch master
, and fetching from origin
maps that branch there to refs/remotes/origin/master
here, so that's the history rebase and pull and probably some others examine by default to find where or whether the histories have diverged. 本地分支master
跟踪origin
的分支master
,并从分支那里的origin
映射中获取到此处的refs/remotes/origin/master
,因此这是对历史的重新定位和拉取,并且可能默认情况下还有其他一些检查以查找历史记录在何处或是否存在已经发散了。
1 The leading +
just means "don't complain if the fetch abandons history", which is of course exactly how you want fetch to operate when you're simply tracking what's going on with a remote's refs. 1前导+
只是表示“如果fetch放弃了历史,请不要抱怨”,这当然就是您在简单地跟踪远程ref的发生情况时希望fetch进行操作的方式。 See the fetch docs for more of its default behavior, eg there's times when you want tags fetched, times when you don't 有关更多默认行为,请参见获取文档,例如,有时需要获取标签,有时不获取标签
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.