`git tag` sorted in chronological order of the date of the commit pointed to

前端 未结 7 1707
礼貌的吻别
礼貌的吻别 2020-12-13 12:44

The output from git tag is ordered alphabetically. I would like it to be ordered chronological (the date of the commits they are assigned to, not the date on wh

相关标签:
7条回答
  • 2020-12-13 12:46

    Try this:

    git for-each-ref --sort=taggerdate --format '%(refname) %(taggerdate)' refs/tags
    

    It works perfectly and very fast for me.

    Refer to How can I list all tags in my Git repository by the date they were created?

    0 讨论(0)
  • 2020-12-13 12:51

    For information, to get it in reverse order, prefix it with "-"

    git tag --sort=-taggerdate
    
    0 讨论(0)
  • 2020-12-13 12:56

    Just tested with git 2.8.0:

    git tag --sort=committerdate
    

    For a full list of field names you can use, see https://git-scm.com/docs/git-for-each-ref#_field_names

    For commit and tag objects, the special creatordate and creator fields will correspond to the appropriate date or name-email-date tuple from the committer or tagger fields depending on the object type. These are intended for working on a mix of annotated and lightweight tags.

    Fields that have name-email-date tuple as its value (author, committer, and tagger) can be suffixed with name, email, and date to extract the named component.

    0 讨论(0)
  • 2020-12-13 12:58
    git tag | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort | awk '{print $4}'
    
    0 讨论(0)
  • 2020-12-13 12:59

    As Alexander pointed out it should be

    git tag --sort=taggerdate
    

    for correct chronological order.

    edit: * iff you're interested in the date the tags where pushed, if you're interested in the date of the commits, it should be "commiterdate"

    0 讨论(0)
  • 2020-12-13 13:06

    In git 2.3.3 I can just do this to get them sorted by date:

    git tag --sort version:refname
    

    PS: For the record, I also answered the same thing on a duplicate question

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