我使用的是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
我想通过giitpython获得字符串"release/1.2.3"。
您可以遍历标签并将每个标签提交与当前头部提交进行比较:
next((tag for tag in repo.tags if tag.commit == repo.head.commit), None)
看起来你可以用GitCmd调用describe
来得到你想要的。
g = Git(git_dir)
rval = g.describe()
我看不出有什么方法可以直接访问这些信息