pull requests show changes which are already merged in destination branch
Asked by Vinay Talla:

Below is sequence of steps performed to validate missing lines in Bitbukect:

created clone branches for dev, stage and master as dev-XCC-2780, stage-XCC-2780, master-XCC-2780  

<br />

created a local branch XCC-2780 from master and added a line "# BitBucket Missing Files XCC-2780, created branch from master" in the file "Clair-Setup/clairScanImages.sh"  

<br />

merged XCC-2780(local branch) to master-XCC-2780(master clone)  

<br />

created branch XCC-2780-1 from dev and made same changes as above and merged to dev-XCC-2780  

<br />

also merged changes from dev-XCC-2780 to stage-XCC-2780  

<br />

As above changes already merged to master-XCC-2780 from branch XCC-2780(local branch), so the pull request from stage-XCC-2780 to master-XCC-2780 should be empty but we see same changes been displayed.


Answers:
author: Patrik S
body: Hello [@Vinay Talla](/t5/user/viewprofilepage/user-id/5519085) ,

and welcome to the Community!

From the information you have shared with us, the reason why you are still seeing these merged changes in the pull requests' diff is that back in 2022 we changed how we compute diffs in bitbucket from previously comparing both branches HEAD's, to now compute diff(topic diff) between the source branch HEAD and the common-ancestor (merge-base). The [merge-base](https://git-scm.com/docs/git-merge-base) is the point in history where the branches started to diverge. This change was described in detail in the following blog post:

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

The fact that the diff shows previous modifications that might be already in the destination branch is simply because, from the diff point of view, they are added in the source branch.

In order to fix this disparity between the branches, you can either rebase or synch the branches on the Pull Requests page by clicking on the **Sync now** button in the Pull Request page.

This will merge the destination branch into the source branch and the diff will show only the "new" changes introduced by the source branch of the pull request. For more details on that please refer to [How to see changes to a destination branch in a Pull Request](https://bitbucket.org/blog/improving-performance-on-complex-diffs#:~:text=How%20to%20see%20changes%20to%20the%20destination%20branch%20in%20a%20pull%20request).

Hope that helps! Let me know in case you have any questions.

Thank you, [@Vinay Talla](/t5/user/viewprofilepage/user-id/5519085) !

Patrik S

comments: author: Vinay Talla
body: Hi [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) ,  

Thanks for your reply it worked well, but the point is syncing the branches before merging pull request will result in loss of files or code?


author: Patrik S
body: Hello [@Vinay Talla](/t5/user/viewprofilepage/user-id/5519085) ,

Great to hear that it worked! The sync between branches is actually a merge operation behind the scenes, where the new changes in the destination branch of the pull request since it was branched off are merged into the source branch.

Given that it's a merge operation, there's no loss of files or code.

Thank you, [@Vinay Talla](/t5/user/viewprofilepage/user-id/5519085) !

Patrik S


author: Vinay Talla
body: Hi [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) , Thanks for your reply  

if possible can use provide me the what could be the base url to be used for below REST API reference:  
<https://developer.atlassian.com/server/bitbucket/rest/v803/api-group-sync/#api-sync-latest-projects-projectkey-repos-repositoryslug-synchronize-post>  

is possible to automate sync operation using api we are using Bitbucket Cloud Edition


author: Patrik S
body: Hello [@Vinay Talla](/t5/user/viewprofilepage/user-id/5519085) ,

The API endpoint you linked is for Bitbucket Server, not Bitbucket Cloud.

For Bitbucket Cloud, I'm afraid there's not yet a public API endpoint to execute the Sync operation in a pull request. We do have a feature request opened with our development team to implement such an endpoint, which you can access using the following link:

* <https://jira.atlassian.com/browse/BCLOUD-20489>

I encourage you to add your vote to that feature request to demonstrate your interest and help our product managers understand the demand. Feel free to also add yourself as a watcher in case you want to be notified by email of any future updates.

Thank you, [@Vinay Talla](/t5/user/viewprofilepage/user-id/5519085) !

Patrik S


author: Vinay Talla
body: Hello [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) , Thanks for your reply, i have voted the issue hope they develop the endpoint which would be much helpful.


Tags: atl-esc

bitbucket-cloud

cloud