3

Is there a way to compare two commits in Bitbucket server?

For bitbucket cloud, you can enter a URL as follows into your browser: https://bitbucket.org/OWNER/PROJECT/branches/compare/commit2..commit1

(per this discussion: https://bitbucket.org/site/master/issues/4779/ability-to-diff-between-any-two-commits).

The same thing (as well as lots of other functionality) does not seem to work in Bitbucket server as I get a 404 error.

Matthew Dresser
  • 11,273
  • 11
  • 76
  • 120
  • Coming in Bitbucket Server 6.3 it seems https://jira.atlassian.com/browse/BSERV-2550 –  Aug 08 '19 at 19:43

2 Answers2

4

The https://bitbucket.org/OWNER/PROJECT/branches/compare/commit2..commit1 not supported on Bitbucket Server.

You can use REST API that utilizes to diff arbitrary commits. Here is the documentation on that REST API endpoint.

The command line for diffs is: "git diff A B", where it shows the changes from A to B. The 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/?since=A&until=B. Write the file path you want the diff for after "/diff/" and before "?since".

Example:

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

https://mybitbucket.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.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • I assume the rest api response is just a git diff formatted as unified diff - no different from just diffing from cmd line, right? What's needed IMO is an html-formatted pretty diff like in the Bitbucket server UI. – timblaktu Dec 10 '19 at 21:30
1

This is supported in Bitbucket Data Center and Server 6.3 although the URL is different.

To compare revisions and see the URL:

  1. Navigate to the repository where you want to compare revisions.
  2. From the sidebar, click Compare.
  3. In the Compare page, from both the Source and Destination dropdown, select any combination of branches, tags, or commits.

Here are the full instructions.

Johan Boberg
  • 3,491
  • 1
  • 22
  • 17