列表标签包含在一个分支 [英] list tags contained by a branch

查看:97
本文介绍了列表标签包含在一个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何列出给定分支包含的标签,相反:

  git tag --contains< commit> ; 

其中只列出包含指定提交的代码。



如果像这样的东西不存在,我该如何测试一个提交是否被另一个提交包含,以便我可以编写脚本?

我可以这样做:

  commit = $(git rev-parse $ branch)$ b $ for $(git tag) 

git log --pretty =%H $ tag | grep -q -E^ $ commit $
done

但我希望有一个更好的方法,因为这可能需要很长时间在一个存储库中有很多标签和提交。

你想:

  git log --simplify-by-decoration --decorate --pretty = oneline$ committish| fgrep'标签:'

但是,更常见的情况是找到最近的标签:

  git describe --tags --abbrev = 0$ committish




  • - tags 将针对轻量级标签进行搜索,请不要使用if您只想考虑带注释的标签。
  • 如果您还想看到通常的数字,请不要使用 - abbrev = 0 '提交最上面'和缩写哈希'后缀(例如v1.7.0-17-g7e5eb8)。

How can I list tags contained by a given branch, the opposite of:

git tag --contains <commit>

Which "only list tags which contain the specified commit".

If something like this does not exist, how do I test whether a commit is contained by another commit so that I can script this?

I could do this:

commit=$(git rev-parse $branch)
for tag in $(git tag)
do
    git log --pretty=%H $tag | grep -q -E "^$commit$"
done

But I hope there is a better way as this might take a long time in a repository with many tags and commits.

解决方案

This might be close to what you want:

git log --simplify-by-decoration --decorate --pretty=oneline "$committish" | fgrep 'tag: '

But, the more common situation is to just find the most recent tag:

git describe --tags --abbrev=0 "$committish"

  • --tags will search against lightweight tags, do not use it if you only want to consider annotated tags.
  • Do not use --abbrev=0 if you want to also see the usual "number of ‘commits on top’ and abbreviated hash" suffix (e.g. v1.7.0-17-g7e5eb8).

这篇关于列表标签包含在一个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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