首页 > 解决方案 > 如何使用 gitpython 获取前一个标签和当前标签之间的 git 日志

问题描述

我正在尝试使用gitpython从特定分支获取前一个标签和当前标签之间的 git 日志,为此我尝试了以下代码

import git
repo = git.Git(r"user\my_name\file")

切换分支

branches = 'Branch-1'
repo.checkout(branches)

然后我试图获取日志

log = repo.log("$(git describe --abbrev=0 --tags --always \"$(git describe --abbrev=0)\"^)..$(git describe --abbrev=0)", '--no-merges')

GitCommandError: Cmd('git') failed 由于: exit code(128) cmdline: git log $(git describe --abbrev=0 --tags --always "$(git describe --abbrev=0)"^) ..$(git describe --abbrev=0) --no-merges stderr: 'fatal: ambiguous argument '$(git describe --abbrev=0 --tags --always "$(git describe --abbrev=0 )"^)..$(git describe --abbrev=0)':未知版本或路径不在工作树中。使用 '--' 将路径与修订分开,如下所示:'git [...] -- [...]''

下面的代码给出了当前标签

git describe --abbrev=0 --tags --always \"$(git describe --abbrev=0)\"^

这给出了前一个标签

git describe --abbrev=0

但是在命令行中,我尝试首先切换到该特定分支,然后执行

 git log $(git describe --abbrev=0 --tags --always "$(git describe --abbrev=0)"^)..$(git describe --abbrev=0)

上面的命令给了我想要的输出,但是使用gitpython我无法得到,请帮我解决这个问题。

标签: python-3.xgit-branchgit-loggit-taggitpython

解决方案


推荐阅读