如何以编程方式确定Git的结账是一个标签,如果是这样,什么是变量名称 [英] How to programmatically determine whether the Git checkout is a tag and if so, what is the tag name

查看:157
本文介绍了如何以编程方式确定Git的结账是一个标签,如果是这样,什么是变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Unix或GNU脚本环境(例如一个Linux发行版,Cygwin的,OSX),什么是确定当前是否结账是一个Git标签的最佳方式。如果它是一个标签,我怎么能确定标签的名字吗?

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine whether the current checkout is a Git tag. If it is a tag, how can I determine the tag name?

一个使用这种技术会自动标记释放(如 svnversion,如果将与Subversion一样)。

One use of this technique would be automatically labeling a release (like svnversion would do with Subversion).

请参阅我关于<一个相关的问题href=\"http://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch\">programmatically检测的Git分支。

推荐答案

你的问题解决方案是使用

git describe --exact-match HEAD

(这只会考虑的注释的标签,但你应该使用注释,甚至可能用于标记释放签署标签)。

(which would consider only annotated tags, but you should use annotated and probably even signed tags for tagging releases).

如果你要考虑所有标签,也轻便的标签(这通常是用于本地标记),你可以使用 - 标签选项​​:

If you want to consider all tags, also lightweight tags (which are usually used for local tagging), you can use --tags option:

git describe --exact-match --tags HEAD



但我认为你有 XY问题在这里,在你在问关于可能解决的问题的问题,而不是问的问题一个问题......它可以有更好的解决方案。

But I think you have "XY problem" here, in that you are asking question about possible solution to the problem, rather than asking question about a problem... which can have better solution.

您的问题解决的办法是看看Git是如何做它的 GIT-VERSION-GEN 的剧本,以及它如何使用它在它的 Makefile文件

The solution to your problem is to take a look how Git does it in GIT-VERSION-GEN script, and how it uses it in its Makefile.

这篇关于如何以编程方式确定Git的结账是一个标签,如果是这样,什么是变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆