10

我使用库gitpython

如果本地 git 在签出标签上,我想获取标签的名称。

repo=git.Repo(repo_dir)
repo.tag # --> tags. But which is the current?

在命令行上,该git工具知道这一点。例子

user@host> git status
HEAD detached at release/1.2.3

我想通过 gitpython 获取字符串“release/1.2.3”。

4

2 回答 2

14

您可以遍历标签并将每个标签提交与当前的头部提交进行比较:

next((tag for tag in repo.tags if tag.commit == repo.head.commit), None)
于 2015-09-11T13:33:54.390 回答
6

看起来你可以通过调用GitCmddescribe得到你想要的东西。

g = Git(git_dir)
rval = g.describe()

我看不到任何直接访问此信息的方法。

于 2015-09-11T12:58:06.163 回答