[英]git fetch does not update .git/refs/remotes/origin/master
I have a local git repository cloned from a central server. 我有一个从中央服务器克隆的本地git存储库。 The last commit of my local master branch is commit 1 . 我的本地master分支的最后一个提交是commit 1 。
The central repository has a new commit 2 in master branch. 中央存储库在master分支中有一个新的commit 2 。
I ran git fetch origin master
to update my local refs, I found refs/remotes/origin/master
does not update. 我运行git fetch origin master
更新了我的本地引用,我发现refs/remotes/origin/master
没有更新。
And then I checked .git/FETCH_HEAD
. 然后我检查了.git/FETCH_HEAD
。 This is, however, already commit 2 但是,这已经提交了2
My local config for the fetch: 我的本地配置:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = #########
Also I am able to login to central and check the bare repository there. 另外,我能够登录到Central并检查那里的裸仓库。 project.git/refs/heads/master
is commit 2 project.git/refs/heads/master
是提交2
Then I tried to run git pull origin master
. 然后我尝试运行git pull origin master
。 Surprisingly, commit 2 is merged into my local repository. 令人惊讶的是, 提交2被合并到我的本地存储库中。
And git diff origin/master
even shows me the diffs between commit 1 and commit 2 . git diff origin/master
甚至向我展示了commit 1和commit 2之间的差异。 But origin and my local repository have the same contents at this point. 但是,此时Origin和我的本地存储库具有相同的内容。
My questions are: 我的问题是:
git fetch
does not download the latest update from origin? 为什么git fetch
不从源下载最新的更新? git pull
still works in this case? 为什么git pull
在这种情况下仍然有效? If you run 如果你跑
git fetch origin
then refs/remotes/origin/master
will be updated. 那么refs/remotes/origin/master
将被更新。
If you specify a single ref to git fetch origin, then it assumes you just want to pull that to FETCH_HEAD 如果您为git fetch origin指定一个引用,则假定您只想将其拉到FETCH_HEAD
you can run 你可以跑
git fetch origin master:refs/remotes/origin/master
and that will also update 这也将更新
When you run git fetch origin master
—or, if you use git pull
, it can do this for you—that should update your origin/master
. 当您运行git fetch origin master
或者,如果您使用git pull
,它可以为您做到这一点), 则应更新您的origin/master
。
This kind of updating, however, was first put into Git in version 1.8.4 (released August 2013). 但是,这种更新最初是在1.8.4版(2013年8月发布)中引入Git的。 Some extremely out of date distributions still use Git version 1.7.x. 一些非常过时的发行版仍使用Git 1.7.x版本。 If you have such an ancient Git, git fetch origin master
will fail to update origin/master
. 如果您拥有如此古老的Git,则git fetch origin master
将无法更新origin/master
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.