Get tags of a commit

戏子无情 提交于 2020-03-27 03:17:49

问题


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

I'd enjoy having something like:

next(repo.iter_commits()).tags

回答1:


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)]


来源:https://stackoverflow.com/questions/34932306/get-tags-of-a-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!