简体   繁体   中英

git fetch does not update .git/refs/remotes/origin/master

I have a local git repository cloned from a central server. The last commit of my local master branch is commit 1 .

The central repository has a new commit 2 in master branch.

I ran git fetch origin master to update my local refs, I found refs/remotes/origin/master does not update.

And then I checked .git/FETCH_HEAD . This is, however, already commit 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. project.git/refs/heads/master is commit 2

Then I tried to run git pull origin master . Surprisingly, commit 2 is merged into my local repository.

And git diff origin/master even shows me the diffs between commit 1 and commit 2 . But origin and my local repository have the same contents at this point.

My questions are:

  1. Why git fetch does not download the latest update from origin?
  2. Why git pull still works in this case?
  3. Is it a problem of my local config or the central config?

If you run

git fetch origin

then refs/remotes/origin/master will be updated.

If you specify a single ref to git fetch origin, then it assumes you just want to pull that to 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 .

This kind of updating, however, was first put into Git in version 1.8.4 (released August 2013). Some extremely out of date distributions still use Git version 1.7.x. If you have such an ancient Git, git fetch origin master will fail to update origin/master .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM