获取提交标签 [英] Get tags of a commit

查看:102
本文介绍了获取提交标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个GitPython Commit对象,我如何获得与此提交相关的标签?​​

Given an object of GitPython Commit, how can I get the tags related to this commit?

我喜欢这样的东西:

next(repo.iter_commits()).tags


推荐答案

问题是标记指向提交,而不是相反。要获得此信息,将需要对所有标签进行线性扫描,以找出哪些标签指向给定的提交。您可能会自己写一些可以做到的事情。以下内容将为您提供一个提交标签的字典:

The problem is that tags point to commits, not the other way around. To get this information would require a linear scan of all tags to find out which ones point to the given commit. You could probably write something yourself that would do it. The following would get you a commit-to-tags dictionary:

tagmap = {}
for t in repo.tags():
  tagmap.setdefault(r.commit(t), []).append(t)

对于给定的提交,您可以从以下位置获取与其关联的任何标签:

And for a given commit, you can get any tags associated with it from:

tags = tagmap[repo.commit(commit_id)]

这篇关于获取提交标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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