Why pull request diff shows files that were already merged in destination branch?

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

Creating a new pull request from a source to destination branch shows files in the diff that were already merged into the destination branch previously.

Cause

This can occur in scenarios where squash merge was used to merge changes from a source branch to destination branch. This is an expected behaviour as Squash merge combines all changes into a single commit and adds the commit into the destination branch.

Steps to reproduce

  • Create a branch named "qa"

  • Add 5 different files and commit these changes into qa branch.

  • Create a Pull request from qa to master branch.

  • Complete the merge option using squash merge strategy.

  • Now all the 5 files are added into master branch using the squash merge.

  • Commit a new file on qa branch and create a new pull request.

  • Now this pull request also shows 6 files by including the 5 files pushed that were already merged in the previous pull request.

How diff is calculated?

$ git merge-base <source-branch> <dest-branch> (Replace source and destination branch with the actual branch names)

$ git diff <mergebase>..<source-branch> --stat (Replace source and destination branch with the actual branch names)

$ git merge-base qa master

772ae3b71695fc622f9f727f097ff67a772121ea

$ git diff 772ae3b71695fc622f9f727f097ff67a772121ea 30d9eb26d8e62266fa16e08d8f5cda1381f6fb23 --shortstat     

6 files changed, 9 insertions(+)

Solution

This is an expected behaviour due to the way the pull request diff is calculated on Bitbucket UI. Bitbucket uses topic diff (2-way three-dot diff) as explained here - https://bitbucket.org/blog/improving-performance-on-complex-diffs

As part of this, the diff is calculated between merge base and the head of source branch. Using the git commands, one can calculate the diff to compare the diff shown on the UI.

Because of the way, the diff is calculated using topic diff method along with squash merge strategy, the diff on the PR UI may show changes that were already merged.

Users can proceed with the merge with their desired merge strategy either on the UI or using git commands. As the files are already existing on the destination branch, git will proceed with merge the new changes that were freshly added to the source branch

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.