Git: distinguish between local and remote tags

后端 未结 2 1507
日久生厌
日久生厌 2021-02-01 16:32

If there are tags in the remote repository, I\'m usually getting them automatically when pulling. When I delete the created local tag (git tag -d )

相关标签:
2条回答
  • 2021-02-01 17:16

    If you're annoyed about these tags being recreated when you run git pull, you turn off the fetching of tags by default with the remote.<remote-name>.tagopt config setting. e.g. if the remote is origin, then you can do:

    git config remote.origin.tagopt --no-tags
    

    Update: to address your comment, the reason that I suggest this is that there's not an obvious way to tell the difference between a tag that was created locally and one that was fetched from a remote. There's also no reflog for tags. So, my suggestion is to suppress automatic fetching of tags - you can then fetch them yourself into a different namespace. For example, you could do:

    git fetch origin +refs/tags/*:refs/tags/origin/*
    

    ... and perhaps create an alias for that. Then when you want to fetch tags, they'll be named, for example, refs/tags/origin/tag1 instead of refs/tags/tag1.


    If you want this to happen automatically, you could change your .git/config to list multiple refspecs for fetching, e.g.:

     [remote "origin"]
          url = whoever@whereever:whatever.git
          fetch = +refs/heads/*:refs/remotes/origin/*
          fetch = +refs/tags/*:refs/tags/origin/*
    

    ... which is suggested in Pro Git.

    0 讨论(0)
  • 2021-02-01 17:28

    a tag isn't "local" or "remote": it is associated to a commit, which can part of multiple branches, including ones in the remotes namespace.

    Get tag SHA1 of the commit referenced by a tag

    git show -s 'TAG_NAME^{commit}' --format='%H'
    

    , and do a :

    git branch -a --contains SHA1
    

    If you see

     remotes/aRemoteRepoName/aBranch
    

    you know that tag references a commit you have fetched from a remote repo.

    As Chris mentions:

    git branch -a --contains TAGNAME
    

    will dereference the tag and gives the answer in one go.

    0 讨论(0)
提交回复
热议问题