Git diff show different files than PR (Pull Request)
Asked by jhownfs:

Hi Guys, how are you?

I noticed that when I do a git diff between the source and destination branch, more files appear than in the PR (pull request), for some reason, which I still don't understand.

example: **git diff --name-only origin/develop origin/qa**.

PR show - file 1, file 2, file 3.

git diff show - file 1, file 2, file 3, **file 4, file 5**

Does anyone know the reason for this behavior? why does diff perish more files than in PR?


Answers:
author: Theodora Boudale
body: Hi [@jhownfs](/t5/user/viewprofilepage/user-id/2075310),

The diff command you are using is equivalent to the two-dot diff command

```
git diff --name-only origin/develop..origin/qa
```

The two dot diff will show changes in both the source and the destination branches.

The pull requests diff in Bitbucket Cloud is using a three-dot diff instead

```
git diff --name-only origin/develop...origin/qa
```

This type of diff will show only changes in the source branch, starting at a common ancestor of both branches. It will not show any changes made to the destination branch.

If **file 4** and **file 5** were changed in the destination branch only, this explains why they will not show in the PR diff on Bitbucket Cloud site.

If you want to see the changes made to the destination branch in a PR, you can merge the destination branch into the source branch.

You can find more details here:

* <https://bitbucket.org/blog/improving-performance-on-complex-diffs>

More information about git diff:

* <https://git-scm.com/docs/git-diff>

> *git diff* \[\<options\>\] \<commit\> \<commit\>...? \<commit\> \[--\] \[\<path\>...?\]
>
> This form is to view the results of a merge commit. The first listed \<commit\> must be the merge itself; the remaining two or more commits should be its parents. Convenient ways to produce the desired set of revisions are to use the suffixes `^@` and `^!`. If A is a merge commit, then `git diff A A^@`, `git diff A^!` and `git show A` all give the same combined diff.
> *git diff* \[\<options\>\] \<commit\>..\<commit\> \[--\] \[\<path\>...\]
>
> This is synonymous to the earlier form (without the `..`) for viewing the changes between two arbitrary \<commit\>. If \<commit\> on one side is omitted, it will have the same effect as using HEAD instead.
> *git diff* \[\<options\>\] \<commit\>...\<commit\> \[--\] \[\<path\>...\]
>
> This form is to view the changes on the branch containing and up to the second \<commit\>, starting at a common ancestor of both \<commit\>. `git diff A...B` is equivalent to `git diff $(git merge-base A B) B`. You can omit any one of \<commit\>, which has the same effect as using HEAD instead.

Kind regards,  
Theodora

comments: author: Denis
body: Hi Theodora,

I am sorry to say that this choice to use diff ... induces misunderstanding.

At the very least, bitbucket should display the "real" commit hash used for diff, explaining that this is the most recent common ancestor. Because at the moment, all it does is spreading confusion, as bitbucket displays a commit hash that is not used for the diff.  

I posted a screenshot to illustrate this.  
![bitbucketDiffExplained.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/305877i6258C972245C723A/image-size/large?v=v2&px=999 "bitbucketDiffExplained.PNG")


author: Theodora Boudale
body: Hi Denis,

Thank you for reaching out.

Can you please confirm if you are using Bitbucket Cloud (repos hosted in <https://bitbucket.org/>) or Bitbucket Server (different, custom URL)?

This question concerns Bitbucket Cloud, but I can't find a Bitbucket Cloud account with your email address.

Kind regards,  
Theodora


author: Denis
body: Hello :)  

I use a private company Bitbucket Server. I hope I don't have to tell you which, because I am not in charge of commercial aspects


author: Theodora Boudale
body: Hi Denis,

Bitbucket Server has a different source code base than Bitbucket Cloud. Support for Server products ends on Feb 15, 2024 so there will be no new features available on the Server version. If you have a Bitbucket Data Center license instead, you can reach out to the support team via <https://support.atlassian.com/contact/#/> and ask for a feature request to be created about what you're asking.

Kind regards,  
Theodora


author: Denis
body: We have the data center version, but I understand this "diff ..." was due to performance issue so, will it have any effect that I make a ticket to our support ? :)  

In any case thank for your time.


author: Theodora Boudale
body: Hi Denis,

The support will not be able to change the diff algorithm. There is an existing feature request where you can add your feedback and vote: <https://jira.atlassian.com/browse/BSERV-7375>

You mentioned something earlier about showing the common ancestor in the PR along with an explanation. The support team can help create a feature request for that too.

Kind regards,  
Theodora


author: Denis
body: Will definitly do :) thank you Theodora !


author: Theodora Boudale
body: You are very welcome, Denis! Please feel free to reach out if you need anything further!


Tags: bitbucket-cloud

cloud