How to diff arbitrary commits using REST API

Still need help?

The Atlassian Community is here for you.

Ask the community

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

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles 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

Purpose

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.


    https://MyStash.com/rest/api/latest/projects/STASH/repos/stash/changes?since=689fcf1017dc944ab976433a9ead8f2912d83622&until=a222a1f58c17f9164eb498eeaadde94675a49467
    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:

     

    https://MyStash.com/rest/api/latest/projects/STASH/repos/stash/diff?since=689fcf1017dc944ab976433a9ead8f2912d83622&until=a222a1f58c17f9164eb498eeaadde94675a49467



Last modified on Feb 14, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.