123456789101112131415161718192021222324 |
- from git import Repo
- def debug_commit_changes(repo_path, commit_hash, target_files=None):
- repo = Repo(repo_path)
- commit = repo.commit(commit_hash)
- if not commit.parents:
- print("Initial commit, no parent to compare")
- return
- parent = commit.parents[0]
- # 强制生成文本差异,忽略重命名
- diffs = parent.diff(commit, create_patch=True, no_renames=True)
- for diff in diffs:
- path = diff.a_path if diff.a_path else diff.b_path
- print(f"文件: {path} ({diff.change_type})")
- print(f"代码变更: {diff.diff.decode('utf-8')}")
- # 调用示例
- debug_commit_changes(r"C:\Users\32965\repo\9992cddb-b7d1-99ec-1bd2-35fdc177e623\test", "a0126f5620377c4894394c918786c6e98d218b6c", target_files=["README.md"])
|