GitPython
provides a python interface to interact with git repositories.
GitPython
Basic UsageTo connect to the repository:
import git
= git.Repo(git_repo_path) repo
where git_repo_path
shall be a
Iterate commits on master
branch:
= list(repo.iter_commits("master"))
commits for commit in commits:
print(commit)
Check the stats
(file modification log) of each commit:
= commits[0]
last_commit print(last_commit.stats.files)
GitPython
also provides low-level interface to execute git command by a more gentle approach. For instance, to execute git show
command:
=True, summary=True) repo.git.show(numstat
This would be interpretd as the shell command
git show --numstat --summary