简体   繁体   English

是否分支。 <name> .merge`代表远程跟踪分支还是上游分支?

[英]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代表远程跟踪分支还是上游分支?

  1. 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, use origin 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, use refs/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/mastermerge = refs/heads/master不像远程跟踪分支(其应该像refs/remotes/<remote>/master ),但一个主题分支,因此它似乎只上游分支给我。

  2. 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代表上游分支,而不是远程跟踪分支。

  3. Is it possible that 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. 本地分支masterdev2是可以从其上游分支更新的本地分支。

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/masterrefs/remotes/origin/master是在上一次git fetchgit 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.

相关问题 git远程跟踪分支返回“请求的上游分支不存在” - git remote tracking branch return "requested upstream branch does not exist" Git 远程跟踪分支和上游分支不同 - Git Remote Tracking Branch and Upstream Branch are different git 上游并跟踪远程分支 - git upstream and tracking a remote branch 是否` <remote> / <branch> 这个`git checkout`命令中的`代表远程分支还是远程跟踪分支? - Does `<remote>/<branch>` in this `git checkout` command represent a remote branch or a remote tracking branch? 上游分支机构是否是远程分支机构? - Does upstream branch have be a remote branch? 当分支。 <branchName> .remote并分支。 <branchName> .merge由Git添加的值? - When branch.<branchName>.remote and branch.<branchName>.merge values added by Git? 上游分支机构和远程跟踪分支机构之间有什么区别? - What is difference between a upstream branch and remote tracking branch? 从上游远程分支合并到本地远程分支 - Merge from an upstream remote branch into a local remote branch 本地和远程分支名称仍然相同“当前分支的上游分支与当前分支的名称不匹配” - Local and remote branch name is same still getting “The upstream branch of your current branch does not match the name of your current branch ” 当前分支没有跟踪信息。 请指定您要合并的分支 - There is no tracking information for the current branch. Please specify which branch you want to merge with
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM