Usage Example:
\nrepo = git.Repo('/path/to/repository')\ndiff_index = repo.head.commit.diff(None, create_patch=True)\nfor diff in diff_index:\n print(f\"{get_change_type_of_diff_item(diff)}: {diff.a_path if diff.a_path else diff.b_path}\")\n```\n
-
I find that when i use commit1.diff(commit2,create_patch = true), chang_type of Diff is aways none. if create_patch = False, i kown that i can get chang_type of Diff , but I can get hunk text. Can i get Diff text ,and meanWhile get chang_type of Diff? |
Beta Was this translation helpful? Give feedback.
-
+1 For getting change_type also set on diff item when create_patch=True. @SongXueZhi Approach depends on your intention for further processing, but you can certainly retrieve the change type info even from a Diff generated with create_patch=True:
Usage Example:
|
Beta Was this translation helpful? Give feedback.
-
If you want to do it in a single line, although it's just slightly inefficient this way:
|
Beta Was this translation helpful? Give feedback.
+1 For getting change_type also set on diff item when create_patch=True.
@SongXueZhi Approach depends on your intention for further processing, but you can certainly retrieve the change type info even from a Diff generated with create_patch=True:
Usage Example: