0

I have the following piece of code to get the list of commit summaries of a specific file:

from git import Repo
repo_working_dir = '<valid directory of the repo>'

repo = Repo(repo_working_dir)

update_file = '<full path of the file whose commit summaries I want to read>'
for commit in list(repo.iter_commits(repo.active_branch,paths=update_file)):
    print(commit.summary)

The above code runs but returns no output. Please let me know where I am going wrong.

4
  • I'm guessing Repo.iter_commits expects a path relative to the git root, and is given a full path. In that case nothing would match and thus nothing would print resulting in no output. Documentation of gitpython does not clarify this at all Commented Mar 14, 2024 at 0:13
  • Thanks I tried passing the path relative to the git root and still it returns nothing
    – Rajesh
    Commented Mar 15, 2024 at 3:35
  • Works for me with a random file from a random gitlab repo that was on my computer, with repo_working_dir being the (absolute) path to the root of my git repo "~/my_code/very_cool_project", and update_file being the (relative) path "README.md" Commented Jan 30 at 13:17
  • Also, you don't need to convert repo.iter_commits(...) to a list, and it also could be causing your problem (converting the very heavy iterable created by this function to a list could take a long time if your commit list is very long) Commented Jan 30 at 14:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.