python - 在 gitpython 的最新提交中打印更改的文件路径
问题描述
我正在尝试在 git python 中获取最新提交和之前的提交之间的更改文件路径。问题是即使最新提交有 1 个更改的文件,它显示的内容也更多。以下是我的代码: -
repo = git.Repo(path)
commits_list = list(repo.iter_commits())
a_commit = commits_list[0]
b_commit = commits_list[-1]
itemDiff = a_commit.diff(b_commit)
for item in itemDiff
print(item.a_path)
我正在尝试针对本地克隆存储库进行此操作。我究竟做错了什么?
解决方案
如果您需要从 repo 中读取,请考虑使用 GitPython 的抽象Pydriller。
for commit in RepositoryMining("repo").traverse_commits():
for modified_file in commit.modifications:
modified_file.new_path # here you have the path of all the files changed in the commit
推荐阅读
- r - 检测二进制序列的模式并在R中使用相同的模式扩展序列
- python - 使用 Gazpacho 和 Pandas 刮擦时输出有限
- gpu - 为什么金属三重缓冲模型在官方示例中很重要?
- macos - macos Catalina 上的 curl 不显示响应正文
- python - 如何在列表理解中使用 if 条件?
- firebase - 从 OnSnapshot 收到的消息的费用
- java - JavaFX:围绕枢轴点移动相机意外行为
- sqlite - 结合 UNION 和 EXCEPT 语句时 sqlite 中的括号
- python - 为什么我的随机森林分类器模型中每棵决策树的 max_depth 都是一样的?
- jsrender - 根据 for 循环中的鉴别器字段加载不同的模板