我正在创建一个用于分析 Git 存储库的工具,但偶然发现了一些应该(看起来)非常简单的东西。
我想创建一个提交到差异的映射(即,对于给定的提交,实际的 blob 逐行更改);我曾尝试使用 GitPython 但没有取得任何成功。我想实现这样的目标:
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
但我不确定如何获取给定提交的所有 blob 更改。 commit_diffs 的形式为:
{ 232d8f39bedc0fb64d15eed4f46d6202c75066b6 : '<String detailing all blob changes for given commit>' }
任何帮助都会很棒。
请您参考如下方法:
我不知道 git diff <commit_a> <commit_b>命令。以下(我认为!)解决了这个问题:
def get_all_commits(REPO_URL):
repo = Repo(REPO_URL)
commits = list(repo.iter_commits())
commmit_diffs = {}
for index, commit in enumerate(commits):
next_index = index + 1
if next_index < len(commits):
commit_diffs[commit.hexsha] = repo.git.diff(commits[next_index], commit)
return commit_diffs
