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: github.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":"\u003cp dir=\"auto\"\u003eI 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.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eCan i get Diff text ,and meanWhile get chang_type of Diff?\u003c/p\u003e","upvoteCount":2,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"\u003cp dir=\"auto\"\u003e+1 For getting change_type also set on diff item when create_patch=True.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003ca class=\"user-mention notranslate\" data-hovercard-type=\"user\" data-hovercard-url=\"/users/SongXueZhi/hovercard\" data-octo-click=\"hovercard-link-click\" data-octo-dimensions=\"link_type:self\" href=\"https://github.com/SongXueZhi\"\u003e@SongXueZhi\u003c/a\u003e 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:\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"def 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\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003edef 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\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eUsage Example:\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"repo = git.Repo('/path/to/repository')\ndiff_index = repo.head.commit.diff(None, create_patch=True)\nfor diff in diff_index:\n print(f\u0026quot;{get_change_type_of_diff_item(diff)}: {diff.a_path if diff.a_path else diff.b_path}\u0026quot;)\n```\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003erepo = 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\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e","upvoteCount":2,"url":"https://github.com/gitpython-developers/GitPython/discussions/1898#discussioncomment-9115310"}}}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:ccd0b36f-e050-74a0-2035-71b645d754ce |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | BB78:27E5CD:F66B8A:13DF242:6B010041 |
| html-safe-nonce | 8a949389017c981c70d9617efd1862fab9fe9a37e11471e512ad14707881cc96 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjc4OjI3RTVDRDpGNjZCOEE6MTNERjI0Mjo2QjAxMDA0MSIsInZpc2l0b3JfaWQiOiIxNjA0MTMyNjQxNDYyODc4Mjc0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9eee8b89891153aa12678bb8bd9241146f62d9cba00ae3933cff5bdf5e1b3d4c |
| 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 | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width