Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我使用库gitpython
如果本地 git 在签出标签上,我想获取标签的名称。
repo=git.Repo(repo_dir) repo.tag # --> tags. But which is the current?
在命令行上,该git工具知道这一点。例子
git
user@host> git status HEAD detached at release/1.2.3
我想通过 gitpython 获取字符串“release/1.2.3”。
您可以遍历标签并将每个标签提交与当前的头部提交进行比较:
next((tag for tag in repo.tags if tag.commit == repo.head.commit), None)
看起来你可以通过调用GitCmddescribe得到你想要的东西。
describe
g = Git(git_dir) rval = g.describe()
我看不到任何直接访问此信息的方法。