Why does comparisons sometime yield different results? #198543
-
🏷️ Discussion TypeQuestion BodyI use the URL compare command in the browser to compare one branch to another in a repo. Doing something like this: https://github.com/MyOrganization/MyRepo/compare/branch1...branch2 In comparing some branches which are closely related, GitHub will report them being identical. That's cool and all, but just for grins and giggles, I thought I would switch the 2 branches around. Sometimes they were still marked as being identical. But sometimes they were not marked as being identical. Why is that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Thank you very much for this explanation! I had thought that the compare function would compare only the latest commit to each branch. I didn’t realize that it compares the ancestry of commits. That does make a difference.
Rod
From: Madireddy Meena Mahanth Harinadh ***@***.***>
Sent: Friday, June 12, 2026 11:13 PM
To: community/community ***@***.***>
Cc: Falanga, Rod, DOH ***@***.***>; Author ***@***.***>
Subject: [EXTERNAL] Re: [community/community] Why does comparisons sometime yield different results? (Discussion #198543)
CAUTION: This email originated outside of our organization. Exercise caution prior to clicking on links or opening attachments.
GitHub's compare view is not always symmetric because the order of the branches matters.
When you use:
branch1...branch2
GitHub treats one branch as the base and the other as the comparison branch. It determines what commits are reachable from one branch but not the other, using their common ancestor (merge base).
If both branches ultimately point to the same commit, GitHub may report that they are identical regardless of order. However, if the branches have different commit histories (for example due to rebases, cherry-picks, or different merge paths) while producing the same file contents, reversing the comparison can yield different results.
In other words, GitHub is comparing commit ancestry, not just the final file state.
A common example is when:
branch2 contains all commits from branch1 plus additional commits → comparing branch1...branch2 shows those extra commits.
Reversing the comparison changes which branch is considered the source of the changes, so the result may differ.
If you're seeing a case where one direction says the branches are identical and the other does not, it would be interesting to see the branch graph (git log --graph --oneline --all) because rebases or cherry-picks are often involved.
-
Reply to this email directly, view it on GitHub<#198543?email_source=notifications&email_token=A6LUKRM7RSBCYZAIIK5QZET47TPF5A5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZSHA3DQMBUUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVRTG633UMVZF6Y3MNFRWW#discussioncomment-17286804>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A6LUKRL5MFVPE4BNIMFAPPD47TPF5AVCNFSNUABIKJSXA33TNF2G64TZHMZTAMJVG4ZTGNBUHNCGS43DOVZXG2LPNY5TCMBSGI4DQNBUUF3AE>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/A6LUKRM74VNRXHMXTKCOOZT47TPF5A5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZSHA3DQMBUUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVJTG633UMVZF62LPOM> and Android<https://github.com/notifications/mobile/android/A6LUKRJE5U7X4H6XYXXPDV347TPF5A5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZSHA3DQMBUUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVZTG633UMVZF6YLOMRZG62LE>. Download it today!
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
Beta Was this translation helpful? Give feedback.
-
|
GitHub’s compare view is not always symmetric because the order of the branches matters. It compares commit ancestry using the common ancestor (merge base), not just the latest commit or final file contents. So reversing branch1...branch2 can produce different results, especially when rebases, cherry-picks, or different merge paths are involved. |
Beta Was this translation helpful? Give feedback.
GitHub’s compare view is not always symmetric because the order of the branches matters. It compares commit ancestry using the common ancestor (merge base), not just the latest commit or final file contents. So reversing branch1...branch2 can produce different results, especially when rebases, cherry-picks, or different merge paths are involved.