How to list all tags pointing to a specific commit in git

后端 未结 6 751
独厮守ぢ
独厮守ぢ 2020-12-02 15:26

I have seen the commands git describe and git-name-rev but I have not managed to get them to list more than one tag.

Example: I have the sh

相关标签:
6条回答
  • 2020-12-02 15:35

    For current commit you can use

    git tag --points-at $(git log -n1 --pretty='%H')
    
    0 讨论(0)
  • 2020-12-02 15:36

    git tag --points-at HEAD

    Shows all tags at HEAD, you can also substitute HEAD with any sha1 id.

    0 讨论(0)
  • 2020-12-02 15:36
    git for-each-ref --format='%(objectname) %(refname:short)' refs/tags/ |
      grep ^$commit_id |
        cut -d' ' -f2

    Pity it can’t be done more easily. Another flag on git tag to include commit IDs could express that git for-each-ref invocation naturally.

    0 讨论(0)
  • 2020-12-02 15:40

    You can use:

    git tag --contains <commit>
    

    that shows all tags at certain commit. It can be used instead of:

    git tag --points-at HEAD
    

    that is available only from 1.7.10.

    0 讨论(0)
  • 2020-12-02 15:48

    The following command does the job, but directly parse the content of the .git directory and thus may break if the git repository format change.

    grep -l -r -e '^48eb354' .git/refs/tags|sed -e 's,.*/,,'
    
    0 讨论(0)
  • 2020-12-02 15:54

    git show-ref --tags -d | grep ^48eb354 | sed -e 's,.* refs/tags/,,' -e 's/\^{}//'

    should work for both lightweight and annotated tags.

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