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
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
insideorderBy
, as seen inEach time, you would start the query with:
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).
in the case of the repository listed in the original post the clone is very small (the fetch also took less than a second):
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
I’m using this one-liner via an alias short-cut
which sorts, and gives a nice overview of the last tags plus some further info.