git fetch, FETCH_HEAD and origin/master

后端 未结 4 921
一个人的身影
一个人的身影 2020-11-29 04:38

I\'m very new to git and I\'m having trouble with a simple fetch operation.

I\'m trying to fetch a coworker\'s progress from his repository. At first I

4条回答
  •  旧时难觅i
    2020-11-29 05:15

    Since git 1.8.4 (August 2013), git fetch will update the remote tracking branch! Not just FETCH_HEAD.

    See commit f269048 from Jeff King (peff):

    When we run a regular "git fetch" without arguments, we update the tracking refs according to the configured refspec.
    However, when we run "git fetch origin master" (or "git pull origin master"), we do not look at the configured refspecs at all, and just update FETCH_HEAD.

    We miss an opportunity to update "refs/remotes/origin/master" (or whatever the user has configured). Some users find this confusing, because they would want to do further comparisons against the old state of the remote master, like:

    $ git pull origin master
    $ git log HEAD...origin/master
    

    But that supposes you have set your repo to fetch branches:

    git config remote.origin.fetch
    

    If empty:

    git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
    

提交回复
热议问题