I am creating a tool for analysis of a Git repository, but have stumbled at something that should (seemingly) be quite simple.
I want to create a mapping of commits to diffs (i.e. actual blob changes line by line for the given commit); I have tried using GitPython but haven't had any success. I would like to achieve something like this:
def get_all_commits(REPO_URL):
chromium_repo = Repo(REPO_URL)
commits = list(chromium_repo.iter_commits())
commmit_diffs = {}
for commit in commits:
diff = # get all blob changes for commit
commit_diffs[commit.hexsha] = diff
return commit_diffs
but am not sure how to get all blob changes for a given commit. commit_diffs
would be in the form:
{ 232d8f39bedc0fb64d15eed4f46d6202c75066b6 : '<String detailing all blob changes for given commit>' }
Any help would be great.
I was unaware of the
git diff <commit_a> <commit_b>
command. The following (I think!) solves the issue: