Search code examples
pythongitgitpython

GitPython: retrieve changed files between commits in specific sub directory


The repo structure looks like this:

- folder_a
- folder_b
- folder_c
- ...

I am particularly interested in the files that changed in a specific commit, but only the ones in folder_a. My solution is

for filename, details in commit.stats.files.items():
  if not filename.startswith('folder_a'):
     continue
  # ...

but it seems the performance is not quite good if there are a great number of files in the other folders. Is there any better way to skip the files I don't care about?


Solution

  • If I understand correctly : you want stats on modifications from a commit, only on one specific subfolder.

    Using plain git :

    git show [commit] --stat folder_a
    

    will display exactly what you want.

    Have a look at what : git.show('<commit identifier>', '--stat', 'folder_a'); returns in your python script.