git fetch vs. git fetch origin master have different effects on tracking branch

后端 未结 3 1554
广开言路
广开言路 2020-12-04 14:56

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 explana

3条回答
  •  不知归路
    2020-12-04 15:29

    The answer lies in the messages you get back from git fetch. In the first case, when you fetch without providing a refspec, you'll see that the remote tracking branches are updated:

    remote: Counting objects: 5, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From /depot
       c67d1c8..1941673  master     -> origin/master
    

    Note how the message says that origin/master is updated with the master from the origin.

    Now in the second case, where you specify the refspec, you get something altogether different:

    remote: Counting objects: 5, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From /depot
     * branch            master     -> FETCH_HEAD
    

    So when you specify the refspec, the remote tracking branch (origin/master) is NOT updated, only FETCH_HEAD.

    The end result is that you'll appear to be ahead of origin/master when you're not really. I can't imagine why this behavior would be desirable, but it's definitely an interesting little quirk of the fetch command.

提交回复
热议问题