本文介绍了git fetch vs. git fetch origin master对跟踪分支有不同的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这主要是好奇心的本质,因为我试图熟悉Git。我已经看过'git fetch'的文档,但是我没有看到下面的明显解释。 1)从一个中央仓库中,比如说GitHub,我克隆一个名为的仓库,网站名为。 / code>在两台机器上, HostA 和 HostB 。
$ b 2)在 HostA 上,我修改了一个文件,比如 README。 txt ,并提交它。

此时在 HostA 上,提交分支 master 和
origin / master 与预期不同,因为我还没有推出

  git show master 
git show origin / master

报告不同的散列值(因为 master 有变化, origin / master 不会)



3)一旦我推,他们在那之后也是这样。




4)现在,在 HostB 上,如果我做了以下操作:

  git fetch 
git merge FETCH_HEAD

之后,在HostB 当使用 git show 和 origin / master 报告相同的散列>

但是

如果我在 HostB

  git fetch origin master 
git merge FETCH_HEAD



  git show origin 
git show origin / master

/ code>

报告不同的哈希值



跟踪分支 origin / master 不会更新,直到我做了一个普通的 git fetch



这是为什么?

解决方案

如果您的分支有关联,这意味着它的配置如下所示:

  git config branch。[branch-name] .remote [remote-name] 
git config branch。[branch-name] .merge [remote-master]

这两个命令的区别在于:

 < refspec> 




快速转发与之匹配的本地裁判

让我再说一遍:

如果< dst> 不是空字符串,与之匹配的本地引用使用< src> 快速转发。

知道:




  • git fetch 相当于 git fetch origin master:master (来自分支配置的默认值),所以它会更新远程跟踪麸皮ch: refspec的目的地是为您指定的


  • git fetch origin master 相当于 git fetch origin master:,而不是 git fetch origin master:master ;它在 FETCH_HEAD中存储' master '分支(远程' origin ')的获取值,而不在' master '分支或远程追踪'远程/原产地/主人'分支(来自的你没有指定你的refspec的目的地



This is mostly of the nature of a curiosity as I'm trying to get familiar with Git. I have looked at the documentation for 'git fetch' but I don't see an obvious explanation for the below. Thanks in advance, and apologies if this is howlingly obvious.

1) From a central repository, say GitHub, I clone a repository named website on each of two machines, HostA and HostB.

2) on HostA, I make a change to a file, say README.txt, and commit it.
At this point on HostA, the commits for branches master andorigin/master are, as expected different since I haven't pushed yet

git show master
git show origin/master

report different hashes (since master has the change and origin/master does not)

3) Once I push, they are after that the same.


4) Now, over on HostB, if I do the following:

git fetch
git merge FETCH_HEAD

afterwards, on HostB master and origin/master report the same hash when queried with git show

BUT

if instead I had done, on HostB:

git fetch origin master
git merge FETCH_HEAD

at that point the hashes still differ.

git show origin
git show origin/master

report different hashes

The tracking branch origin/master isn't updated until I do a plain git fetch

Why is this?

解决方案

If your branch has an associated remote tracking branch that means its configuration is like:

git config branch.[branch-name].remote [remote-name]
git config branch.[branch-name].merge [remote-master]

The key part of git fetch which explain the difference between the two commands is:

<refspec>

Let me repeat it:

if <dst> is not empty string, the local ref that matches it is fast-forwarded using <src>.
Knowing that:

  • git fetch is equivalent to git fetch origin master:master (from the default value of your branch config), so it will update the remote tracking branch: the destination of the refspec is specified for you.

  • git fetch origin master is equivalent to "git fetch origin master:", not to "git fetch origin master:master"; it stores fetched value of 'master' branch (of remote 'origin') in FETCH_HEAD, and not in 'master' branch or remote-tracking 'remotes/origin/master' branch (from Jakub Narębski's answer)
    In other words, you didn't specify the destination of your refspec

这篇关于git fetch vs. git fetch origin master对跟踪分支有不同的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:52