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: patch-diff.githubusercontent.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:a413b1b2-56b5-11ee-5d6e-9fdfeb325930 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | 8BD8:BE940:2509550:30C728C:696D8EC4 |
| html-safe-nonce | 76ef2a3960a3c646ed6fed989fe38b3e12f95dab6ac8180af7d05542488e9ae2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QkQ4OkJFOTQwOjI1MDk1NTA6MzBDNzI4Qzo2OTZEOEVDNCIsInZpc2l0b3JfaWQiOiI0MTUzNDY1MDM4OTQ2Nzk5MzAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ead977c5445e3c3cb4f56cf6261051709106c80df2feca2e359985f850257edd |
| 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 | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| 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 | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width