How to diff arbitrary commits using REST API

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

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

BSERV-2550 - Commit-level arbitrary diff (compare commits)

There currently aren't any good ways of diffing arbitrary commits in Bitbucket Server's UI. We have a Feature request BSERV-2550 which addresses this. It's possible to tag commits that you wish to diff and then create a pull request and selecting tags instead of branches, but REST API is also an option. The following may be useful for those who don't like the tag option and also plugin developers.

Solution

Diff Two Commits

  • The command line for diffs is: "git diff A B", where it shows the changes from A to B. Our REST URL looks like /rest/api/latest/projects/KEY/repos/slug/changes?since=A&until=B (where A and B have the same relevance). That will list all the files that changed.

    You can call /rest/api/latest/projects/KEY/repos/slug/diff/<one file>?since=A&until=B. Write the file path you want the diff for after /diff/ and before ?since.

    1 https://MyStash.com/rest/api/latest/projects/STASH/repos/stash/changes?since=689fcf1017dc944ab976433a9ead8f2912d83622&until=a222a1f58c17f9164eb498eeaadde94675a49467
    1 https://MyStash.com/rest/api/latest/projects/STASH/repos/stash/diff/dao-impl/src/main/java/com/atlassian/stash/internal/pull/HibernateRescopeRequestDao.java?since=689fcf1017dc944ab976433a9ead8f2912d83622&until=a222a1f58c17f9164eb498eeaadde94675a49467
  • You will have to include a path after /diff. You can't just ask for the entire diff

    So something like this will return a 400 Bad Request:

    1 https://MyStash.com/rest/api/latest/projects/STASH/repos/stash/diff?since=689fcf1017dc944ab976433a9ead8f2912d83622&until=a222a1f58c17f9164eb498eeaadde94675a49467
Updated on April 15, 2025

Still need help?

The Atlassian Community is here for you.