从远程git存储库中找到最新的git标签 [英] Find latest git tag from the remote git repository
问题描述
我必须从远程git存储库中获取最新的 git标记.我已经使用以下命令来查找最新标签
git ls-remote --tags xxxxx@xxxx.xxxx.net:xxxx.git | grep"\." | grep -v-| grep -v {|排序-n -t.-k3 -k4
这给了我以下输出
c8be4313ae8261214acb6d3d41f9ece8d47a4ad5 refs/tags/v0.2.19e776cff51a8bb15f0539b852a819723d1e37c69参考/标签/v0.2.2ee1f173f4e7da0996af9f7c91e0952bec8c2358b refs/tags/v0.1.35d6777bf2b2e5bae41ae9ab966320c691c1f2ee2 refs/tags/v0.1.46d3040673330ed763bc0c1a6e6cd5dbc82392d4f refs/标签/v0.1.54afd29dc48805053be911a85c6da6b195e96e786参考/标签/v0.1.68d5cc76d50b153f836561bb933b1f5ad488748d1 refs/标签/v0.1.71c0cdebaed828aaef2897c9240b4440898f70766参考/标签/v0.1.8683de590ba8d633c801d2628f4d9de58f9de371a裁判/标签/v0.1.9925797f07cfc94a3af1f56cdabd856e11b222b78 refs/tags/v0.1.10
但是我必须找到最新创建的 v0.2.2 .如何找到最新创建的标记(带有最近创建日期的标记).还有其他方法吗?
您可能需要可访问的最新标签,而不是创建的最新标签:
git describe --tags --abbrev = 0
无论如何,以防万一您确实需要创建最后一个标签:
git确实有两种标签:轻量级标签和带注释的标签.如果您的标签是轻量级的,那么运气不好,您将无法执行此操作,因此无法跟踪创建日期.如果您有权访问存储远程回购的文件系统,则可以尝试检查/refs/tags中文件的时间戳-但是此信息不一定准确(这只是在此特定回购中创建标记文件的时间戳)./p>
但是,对于带注释的标签,您可以获取创建日期.一旦获得了sha(通过ls-tree或其他方式),请运行:
git cat-file -p< sha>
显示标记,消息和创建日期,或仅显示:
git show< sha>
另外还显示引用的提交.
在脚本中使用此信息是可行的(由于日期格式,这可能不容易).
我本来希望您参考有关标签的git内部说明,但事实证明,所有这些信息也在 This gives me following output But I have to find the v0.2.2 which is latest created. how can I find the latest created tag ( tag with latest created date) . Is there any other way to do it? You probably need latest tag reachable, not latest tag created: Anyway, just in case you really need last tag created: git does have two kinds of tags: lightweight and annotated. If your tags are lightweight then tough luck, you can't do this, creation date is not tracked. If you have access to filesystem where your remote repo is stored, then you can try checking timestamps on files in /refs/tags - but this info is not necessarily accurate (it's only timestamp of creation of tag file in this particular repo). For annotated tags, however, you CAN obtain creation date; once you get sha (by ls-tree or other means), run: to show tagger, message and creation date or simply: to additionally show referenced commit, too. Using this information in script is doable (maybe not trivial due to date format). I was going to refer you to git internals description about tags, but turns out, that all this info is also described on ProGit, Git Basics - Tagging. 这篇关于从远程git存储库中找到最新的git标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!c8be4313ae8261214acb6d3d41f9ece8d47a4ad5 refs/tags/v0.2.1
9e776cff51a8bb15f0539b852a819723d1e37c69 refs/tags/v0.2.2
ee1f173f4e7da0996af9f7c91e0952bec8c2358b refs/tags/v0.1.3
5d6777bf2b2e5bae41ae9ab966320c691c1f2ee2 refs/tags/v0.1.4
6d3040673330ed763bc0c1a6e6cd5dbc82392d4f refs/tags/v0.1.5
4afd29dc48805053be911a85c6da6b195e96e786 refs/tags/v0.1.6
8d5cc76d50b153f836561bb933b1f5ad488748d1 refs/tags/v0.1.7
1c0cdebaed828aaef2897c9240b4440898f70766 refs/tags/v0.1.8
683de590ba8d633c801d2628f4d9de58f9de371a refs/tags/v0.1.9
925797f07cfc94a3af1f56cdabd856e11b222b78 refs/tags/v0.1.10
git describe --tags --abbrev=0
git cat-file -p <sha>
git show <sha>