Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to get git patch-id?#1974

Answeredbyjayjoshi64
jayjoshi64 asked this question inQ&A
Discussion options

This is command-line syntax to get patch-id for a commit

git show HEAD | git patch-id

Reference:https://git-scm.com/docs/git-patch-id

Q: How can I get the same output using GitPython?

You must be logged in to vote

I got it to work with this:

def get_patch_id(commit: str) -> str:    """    Get patch-id of a commit.    a patch id is a unique ID for a patch (git show)    ref: https://git-scm.com/docs/git-patch-id    """    with Repo(repo_path) as repo:        with tempfile.TemporaryFile() as temp_file:            # output_stream = BytesIO()            repo.git.show(commit, output_stream=temp_file)            temp_file.seek(0)            return repo.git.patch_id(istream=temp_file).split()[0]

Replies: 2 comments

Comment options

You would have to userepo.patch_id() directly and add options to receive the running process, through which one then can pass the commit to generate a patch-id for. It's cumbersome, and probably easier just toPopen to run git directly.

You must be logged in to vote
0 replies
Comment options

I got it to work with this:

def get_patch_id(commit: str) -> str:    """    Get patch-id of a commit.    a patch id is a unique ID for a patch (git show)    ref: https://git-scm.com/docs/git-patch-id    """    with Repo(repo_path) as repo:        with tempfile.TemporaryFile() as temp_file:            # output_stream = BytesIO()            repo.git.show(commit, output_stream=temp_file)            temp_file.seek(0)            return repo.git.patch_id(istream=temp_file).split()[0]
You must be logged in to vote
0 replies
Answer selected byjayjoshi64
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@jayjoshi64@Byron

[8]ページ先頭

©2009-2025 Movatter.jp