GitPython list all files affected by a certain commit

人走茶凉 提交于 2019-12-22 04:43:28

问题


I am using this for loop to loop through all commits:

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

How can I get a list with the files affected from this specific commit ?


回答1:


Try it

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



回答2:


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}")



回答3:


I solved this problem for SCM Workbench. The important file is:

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

Look at cmdCommitLogForFile() and its helper __addCommitChangeInformation().

The trick is to diff the tree objects.



来源:https://stackoverflow.com/questions/39707759/gitpython-list-all-files-affected-by-a-certain-commit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!