Title: How can i set create_patch=true, and meanwhile get change_type in Diff · gitpython-developers/GitPython · Discussion #1898 · GitHub
Open Graph Title: How can i set create_patch=true, and meanwhile get change_type in Diff · gitpython-developers/GitPython · Discussion #1898
X Title: How can i set create_patch=true, and meanwhile get change_type in Diff · gitpython-developers/GitPython · Discussion #1898
Description: How can i set create_patch=true, and meanwhile get change_type in Diff
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/gitpython-developers/GitPython/discussions/1898
X: @github
Domain: togithub.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"How can i set create_patch=true, and meanwhile get change_type in Diff","text":"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.
\nCan i get Diff text ,and meanWhile get chang_type of Diff?
","upvoteCount":2,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"+1 For getting change_type also set on diff item when create_patch=True.
\n@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:
\ndef get_change_type_of_diff_item(diff_item):\n if diff_item.new_file:\n change_type = 'Added'\n elif diff_item.deleted_file:\n change_type = 'Deleted'\n elif diff_item.renamed_file:\n change_type = 'Renamed'\n elif diff_item.copied_file:\n change_type = 'Copied'\n else:\n change_type = 'Modified'\n return change_type\n
\nUsage 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
","upvoteCount":2,"url":"https://github.com/gitpython-developers/GitPython/discussions/1898#discussioncomment-9115310"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:294668e4-c154-a500-4dc7-bbbf4e606fd0 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | A65C:1D1048:A16725:E23975:69690C16 |
| html-safe-nonce | ee526a2506eb96059c149fa6081860a51a3276cc3212814f4931e4ec38ece821 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjVDOjFEMTA0ODpBMTY3MjU6RTIzOTc1OjY5NjkwQzE2IiwidmlzaXRvcl9pZCI6IjQ1MTQxMDI0NTYyNjUyODA1MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dca76ac5e6270365b26493639904048ef3c44bd916e7e1f036f36eb603e9e779 |
| hovercard-subject-tag | discussion:6449570 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/gitpython-developers/GitPython/1898/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/6f7e513e3513016261d568969f2bc1e199ec30a880ba3da569ebd507581ec3bf/gitpython-developers/GitPython/discussions/1898 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6f7e513e3513016261d568969f2bc1e199ec30a880ba3da569ebd507581ec3bf/gitpython-developers/GitPython/discussions/1898 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e6156bd4ef9f2dc8dadf4c49a8f7ed8532186388cef72eda3ccb9f0ab3b8cfca |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ee2210c3e58153aae53400c942f8a7b4bbb43ec4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width