← 返回首页
How can i set create_patch=true, and meanwhile get change_type in Diff · gitpython-developers/GitPython · Discussion #1898 · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Discussion options

{{title}}

2 You must be logged in to vote
All reactions

+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:

def get_change_type_of_diff_item(diff_item): if diff_item.new_file: change_type = 'Added' elif diff_item.deleted_file: change_type = 'Deleted' elif diff_item.renamed_file: change_type = 'Renamed' elif diff_item.copied_file: change_type = 'Copied' else: change_type = 'Modified' return change_type

Usage Example:

repo = git.Repo('/path/to/repository') diff_index = repo.head.commit.diff…

Replies: 2 comments 1 reply

Comment options

{{title}}

Marked as answer
2 You must be logged in to vote
All reactions
1 reply
Comment options

{{title}}

All reactions
Answer selected by SongXueZhi
Comment options

{{title}}

1 You must be logged in to vote
All reactions
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1897 on April 02, 2024 09:08.

Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu

Select a reply

Loading
👍 1 reacted with thumbs up emoji 👎 1 reacted with thumbs down emoji 😄 1 reacted with laugh emoji 🎉 1 reacted with hooray emoji 😕 1 reacted with confused emoji ❤️ 1 reacted with heart emoji 🚀 1 reacted with rocket emoji 👀 1 reacted with eyes emoji

Footer

© 2026 GitHub, Inc.