GitPython 列出受特定提交影响的所有文件

问题描述 投票:0回答:4

我正在使用这个 for 循环遍历所有提交:

repo = Repo("C:/Users/shiro/Desktop/lucene-solr/")
for commit in list(repo.iter_commits()):
    print commit.files_list  # how to do that ?

如何获得受此特定提交影响的文件列表?

python gitpython
4个回答
22
投票

试试看

for commit in list(repo.iter_commits()):
    commit.stats.files

0
投票
from git import Repo
repo = Repo('/home/worldmind/test.git/')
prev = repo.commit('30c55d43d143189698bebb759143ed72e766aaa9')
curr = repo.commit('5f5eb0a3446628ef0872170bd989f4e2fa760277')
diff_index = prev.diff(curr)
for diff in diff_index:
    print(diff.change_type)
    print(f"{diff.a_path} -> {diff.b_path}")

0
投票

commit.stats.files
有效,但速度很慢。处理大型提交需要几秒钟。

这要快得多:

repo = Repo("C:/Users/shiro/Desktop/lucene-solr/")
for commit in list(repo.iter_commits()):
   print(self.repo.git.show(commit.hexsha, name_only=True).split('\n'))

-5
投票

我为 SCM Workbench 解决了这个问题。重要文件是:

https://github.com/barry-scott/scm-workbench/blob/master/Source/Git/wb_git_project.py

查看 cmdCommitLogForFile() 及其助手 __addCommitChangeInformation()。

诀窍是区分树对象。

© www.soinside.com 2019 - 2024. All rights reserved.