How to get Number of files touched, Number of lines added, Number of lines removed from for commit in repo.iter_commits(branch) using python git?

Viewed 19

I would like to store the following info per commit like so,

for commit in repo.iter_commits(branch):
    author_name=commit.author.name
    commit_id=commit
    commit_authored_date=datetime.datetime.fromtimestamp(commit.authored_date)
    commit_committed_date=datetime.datetime.fromtimestamp(commit.committed_date)
    num_files_touched=?
    num_lines_added=?
    num_lines_removed=?

how can I do this?

1 Answers
for commit in repo.iter_commits(branch):
        author_name=commit.author.name
        commit_id=commit
        commit_authored_date=datetime.datetime.fromtimestamp(commit.authored_date)
        commit_committed_date=datetime.datetime.fromtimestamp(commit.committed_date)
        num_files_touched=commit.stats.total['files']
        num_lines_added=commit.stats.total['insertions']
        num_lines_removed=commit.stats.total['deletions']

This fetches the number of files touched, the number of lines added, and number of lines removed for each commit

Related