显示你在哪个git标签? [英] Show which git tag you are on?

查看:388
本文介绍了显示你在哪个git标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我这样做时:

  git checkout tag1 
git branch

我可以似乎找不到我正在使用的标签。它只记录:

  *(no branch)
master

是否可以找出哪些标签已签出?在上例中,这将是 tag1

解决方案

编辑:JakubNarębski拥有更多git-fu。以下更简单的命令完美地工作:

  git describe --tags 

(或者没有 - tags 如果您签出了带注释的标签,我的标签是轻量级的,所以我需要--tags。)



原始答案如下:

  git describe --exact-match --tags $(git log -n1 --pretty ='%h')

有更多git-fu的人可能会有更优雅的解决方案......

这充分利用了 git-log 报告从您检出的内容开始的日志。 %h 打印缩写哈希。然后 git describe --exact-match --tags 找到与该提交完全匹配的标记(轻量级或注释)。



上面的 $()语法假定您使用的是bash或类似的。


I'm having trouble finding out which tag is currently checked out.

When I do:

git checkout tag1
git branch

I can't seem to find out which tag I'm on. It only logs:

* (no branch)
master

Is it possible to find out which tags are checked out? In the above example, this would be tag1.

解决方案

Edit: Jakub Narębski has more git-fu. The following much simpler command works perfectly:

git describe --tags

(Or without the --tags if you have checked out an annotated tag. My tag is lightweight, so I need the --tags.)

original answer follows:

git describe --exact-match --tags $(git log -n1 --pretty='%h')

Someone with more git-fu may have a more elegant solution...

This leverages the fact that git-log reports the log starting from what you've checked out. %h prints the abbreviated hash. Then git describe --exact-match --tags finds the tag (lightweight or annotated) that exactly matches that commit.

The $() syntax above assumes you're using bash or similar.

这篇关于显示你在哪个git标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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