skip to Main Content

I am using git ls-remote --tags <url> to get the tags from a repository. However, it doesn’t provide any date information. So I wonder if there is any way to get tags with date information without cloning the whole repository. I already check the git ls-remote documents,but I couldn’t find any useful information.
I tried git ls-remote --tags https://github.com/shopify/sarama, and I got:

2ed98903c79815c54f80ab06167a74755e74348c        refs/tags/v1.0.0
3b6fa677e9395c3d7151999974d1b5b36f6ac091        refs/tags/v1.1.0
9bb4a68d57ff6f623363aa172f0a8297aa289ba7        refs/tags/v1.10.0
bd61cae2be85fa6ff40eb23dcdd24567967ac2ae        refs/tags/v1.10.1
0fb560e5f7fbcaee2f75e3c34174320709f69944        refs/tags/v1.11.0
c01858abb625b73a3af51d0798e4ad42c8147093        refs/tags/v1.12.0
bbdbe644099b7fdc8327d5cc69c030945188b2e9        refs/tags/v1.13.0
240fd146ce68bcafb034cc5dc977229ffbafa8ea        refs/tags/v1.14.0
3b1b38866a79f06deddf0487d5c27ba0697ccd65        refs/tags/v1.15.0
f7be6aa2bc7b2e38edf816b08b582782194a1c02        refs/tags/v1.16.0
35324cf48e33d8260e1c7c18854465a904ade249        refs/tags/v1.17.0
a6144ae922fd99dd0ea5046c8137acfb7fab0914        refs/tags/v1.18.0
ec843464b50d4c8b56403ec9d589cf41ea30e722        refs/tags/v1.19.0
fcf765a8b80c7b3a5ba1cb3bb9036261502b1ee8        refs/tags/v1.2.0
...

Obviously, they are not sorted by date. Anyone can solve this problem?

According to Vonc’s answer below, I find a way to get tag info ordered by date. First, use GraphQL Explorer and then type the script below:

query{
      repository(name: "snappy", owner: "golang") {
        refs(refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, last: 100) {
          nodes {
            name
            target {
              __typename
              ... on Tag {
                oid
                name
                tag_message: message
                tagger {
                  email
                  name
                }
                target {
                  oid
                }
              }
              ... on Commit {
                commit_message: message
              }
            }
          }
        }
      }
    }

Then, you can get info ordered by commit_date DESC. Also, you can change ‘DESC’ to ‘ASC’ to reverse the result. I test this in my postman, settings are as below:
url: https://api.github.com/graphql
method: POST
header: Authorization: bearer (my github token)
json_data:

{
    "query": "query{repository(name: "snappy", owner: "golang") {refs(refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, last: 100) { nodes { name target { __typename ... on Tag { oid name tag_message: message tagger { email name } target { oid } } ... on Commit { commit_message: message}}}}}}"
    }

The info you can get is just the same with what you get from graphql explorer.

4

Answers


  1. The only option, without any clone, would be to use a GraphQL API v4, in order to filter tags by commit date with field: TAG_COMMIT_DATE inside orderBy, as seen in

    Each time, you would start the query with:

    refs(refPrefix: "refs/tags/", last: 100, orderBy: {field: TAG_COMMIT_DATE, direction: ASC}) {
    # or
    refs(refPrefix: "refs/tags/", first: 2, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) 
    
    Login or Signup to reply.
  2. One strategy you can use is to make a temporary checkout and only pull the commit objects down (ignoring the blobs and the rest of the commits).

    git init repo
    cd repo
    git config extensions.partialClone true
    git remote add origin https://github.com/shopify/sarama
    time git fetch --filter=blob:none --tags --depth=1 origin
    git tag -l | xargs -t -n1 git log --format=%cd
    

    in the case of the repository listed in the original post the clone is very small (the fetch also took less than a second):

    $ du -hs .
    504K    .
    
    $ git tag -l | xargs -t -n1 git log --format=%cd |& head -10
    git log '--format=%cd' v1.0.0 
    Tue Mar 17 13:48:54 2015 -0400
    git log '--format=%cd' v1.1.0 
    Fri Mar 20 19:21:21 2015 +0000
    git log '--format=%cd' v1.10.0 
    Tue Aug 2 08:43:06 2016 -0400
    git log '--format=%cd' v1.10.1 
    Tue Aug 30 09:25:53 2016 -0400
    git log '--format=%cd' v1.11.0 
    Tue Dec 20 13:06:16 2016 -0500
    
    Login or Signup to reply.
  3. Here’s this feature that I recently got to know (thanks to my mentor).
    GitHub supports subversion, a part of it at least.
    So, you can do

    svn --verbose ls https://github.com/nexB/vulnerablecode/tags
    
    Login or Signup to reply.
  4. I’m using this one-liner via an alias short-cut

    git for-each-ref --sort=-v:refname refs/tags --count 8 --format='%(objectname) %(authordate:short) %(refname) %(align:30) %(authorname) %(end) %(subject)'
    

    which sorts, and gives a nice overview of the last tags plus some further info.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search