我通过以下方式使用gitpython
获得两次提交之间的差异:
def get_inbetween_commit_diff(repo_path, commit_a, commit_b):
repo = Repo(repo_path)
uni_diff_text = repo.git.diff(
"{}".format(commit_a), "{}".format(commit_b), ignore_blank_lines=True, ignore_space_at_eol=True
)
return uni_diff_text
但是,默认的repo.git.diff
显示了带有双点的diff。有没有一种方法可以使用gitpython
实现三点差异?双点和三点差异参考:https://matthew-brett.github.io/pydagogue/git_diff_dots.html
repo.git.diff
直接调用git,所以我认为您可以这样做:
repo.git.diff(
"{}...{}".format(commit_a, commit_b), ignore_blank_lines=True, ignore_space_at_eol=True
)