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: user:token@github.com
IPv4 address: 140.82.113.4
{"@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:0649411b-4fe8-bf3d-8233-b2768f1c3776 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | E338:83634:101C342:158D9AE:6B06546F |
| html-safe-nonce | 0bf1f29c49da2a2ca77a604704e884d42cade6e830bc7651d4034c9b20964df4 |
| visitor-payload | eyJyZWZlcnJlciI6bnVsbCwicmVxdWVzdF9pZCI6IkUzMzg6ODM2MzQ6MTAxQzM0MjoxNThEOUFFOjZCMDY1NDZGIiwidmlzaXRvcl9pZCI6IjQ1Mjk2NDgyMzU0Mjk0NDg3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImNlbnRyYWx1cyJ9 |
| visitor-hmac | b59b30640e58a7200da66f7f4ddef54a1981e012ad75d162fee826689e516cdb |
| 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 | 6324e6ac990fb6befbec840cc0e102a1071c339bfe8f9826bb12de2e3ba1d297 |
| 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 | 7f0aa75f4141d440c6110dc31af7ea7797abb6c4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width