Get time of last commit for Git repository files via Python?

git, python

Solution

With GitPython, this would do the job:

import git
repo = git.Repo("./repo")
tree = repo.tree()
for blob in tree:
    commit = next(repo.iter_commits(paths=blob.path, max_count=1))
    print(blob.path, commit.committed_date)

Note that `commit.committed_date` is in "seconds since epoch" format.

Problem

I have a Git repository with several thousand files, and would like to get the date and time of the last commit for each individual file. Can this be done using Python (e.g., by using something like `os.path.getmtime(path)`)?

Original source

Related problems