如何在 GitPython 中的两个标签之间列出所有更改的文件

How to list all changed files between two tags in GitPython

我可以使用 Git 命令 git log --oneline tag1 tag2 列出两个标签之间的所有提交。然后使用 git show --pretty="" --name-only commitId 列出一次提交中更改的文件。
如何使用 GitPython?

实现此目的

如果你知道 git 命令,你可以在 GitPython 中 use git directly。以git show --pretty="" --name-only HEAD为例:

from git import Repo

# Suppose the current path is the root of the repository
r = Repo('.')
o = r.git.show('HEAD', pretty="", name_only=True)
print(o)
  • HEAD 这样的参数保持不变,作为 non-keyword 个参数。
  • --pretty="" 这样的参数通过删除前导 -- 转换为关键字参数。
  • 通过删除前导 -- 并分配值 True.
  • ,将像 --name-only 这样的标志转换为关键字参数
  • 键和命令中的-转换为_name-only 应该是 name_onlygit for-each-ref 应该是 git.for_each_ref.
  • non-keyword 参数位于关键字参数之前。

命令git log --oneline tag1 tag2 没有列出两个标签之间的提交。它列出了可从两个标签中的任何一个访问的提交。