标签: python git gitpython
答案 0 :(得分:15)
您需要传递name_only关键字参数 - 当发出git命令时,它将自动用作--name-only命令行选项。
name_only
--name-only
以下等同于git diff --name-only HEAD~1..HEAD:
git diff --name-only HEAD~1..HEAD
diff = repo.git.diff('HEAD~1..HEAD', name_only=True) print(diff)