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

Is three a way to do three dot diff between two branches? #1427

Unanswered
iwccsbfb asked this question in Q&A
Discussion options

In command line, I can do git diff master..branch and also git diff master...branch. However, in gitPython, it seems the commit.diff(commit2) is only doing two dot diff. And I couldn't find a way to do three dot diff directly (I have searched through the document and googled around).
I am thinking to find the commit where we branch off, and then do a two way diff - this would be the same as the three way diff of two branches. But it does not work exactly as expected:

# this commit is not the root commit, but the child of the root commit...
commit = list(repo.iter_commits('origin/master..HEAD'))[-1]
diff = commit.diff(repo.head.commit)

Would you have any recommendation?
Thank you.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

I believe I have worked around in following way:

def three_dot_diff_with_master(repo):
 # might be slow when the commit tree is very big
 master_commits = repo.iter_commits('origin/master')
 local_commits = set(repo.iter_commits('HEAD'))
 for commit in master_commits :
 if commit in local_commits:
 break
 diffs = commit.diff(repo.head.commit)

I believe this issue can now be closed. But I'll leave the decision to the project admin.
Thank you

You must be logged in to vote
1 reply
Comment options

The above seems like a custom implementation of git merge-base, which could probably be called with repo.git.merge_base(...) to do the same but much more swiftly.
Maybe that helps alleviating the need for triple-dot syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1426 on April 11, 2022 23:49.

AltStyle によって変換されたページ (->オリジナル) /