Skip to content

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

Description

@iwccsbfb

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.

Activity

  1. iwccsbfb commented on Apr 11, 2022

    @iwccsbfb
    Author

    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

  2. locked and limited conversation to collaborators on Apr 11, 2022
  3. converted this issue into a discussion #1427 on Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions