Are “git fetch --tags --force” and “git pull ” conmutative operations?

后端 未结 3 1320
长情又很酷
长情又很酷 2021-02-06 11:48

Normally the git tags are a fixed reference to a commit. But sometimes they are used to mark some event (last-build, base-line, etc..) and they change

3条回答
  •  难免孤独
    2021-02-06 12:25

    I'm going to answer the following question (which you did not explicitly ask) :

    How can I update automatically a fixed set of tags each time I call git fetch or git pull ?

    We have the exact same situation at my place, and this is how I delt with it .

    By default, the refspec for a remote is :

    [remote "origin"]
        url = git@server:repo # or whatever
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    This is why it only fetches branches from the remote - it only gets refs/heads/* references from the remote.

    This is the default configuration, but you can add whatever references you see fit.


    You can use the refspec to tell git to also fetch refs/tags/last-build from the remote, and to automatically update your local tag :

    [remote "origin"]
        url = git@server:repo # or whatever
        fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = +refs/tags/last-build:refs/tags/last-build
        # this line tells :
        #   - get the 'refs/tags/last-build' (first ref, before ':') from the remote
        #   - store it in my local tag (second ref after, ':')
        #   - allow forced updates (initial '+')
    

    warning : this specific line will trash your local last-build tag on each fetch, and git does not keep a reflog for tags. Given the meaning of such tags, I find this behavior ok.

    If you feel uncomfortable with this, you can specify another local ref :

     # you will see two tags 'last-build' and 'origin/last-build' in your repo :
     fetch = +refs/tags/last-build:refs/tags/origin/last-build
    

    Obviously, add one such line for each relevant tag ...


    reference : refspec doc

提交回复
热议问题