96

I was trying to compare two commits on the same branch (master in this case) in BitBucket and did not find a good answer in any forum, so decided to try their client, SourceTree to see if installing it locally would help and it did.

Therefore, thought it might be useful to add question and answer here.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
ng10
  • 1,660
  • 1
  • 15
  • 19

8 Answers8

101

BitBucket Cloud (bitbucket.org) supports commit comparison on the branch compare page:

  1. Navigate to a repo
  2. Click the '+' menu in the left-nav
  3. Click 'Compare branches and tags'
  4. Paste your commit hashes into the search fields in the branch/tag dropdowns
  5. Click 'Compare'
simhumileco
  • 31,877
  • 16
  • 137
  • 115
Alastair Wilkes
  • 1,425
  • 1
  • 9
  • 3
  • 8
    Thank you! was not aware of this option. However, it did not work for me for two commits on the same branch (master) - not sure why. – ng10 Jul 08 '18 at 20:02
  • 2
    -1 even it this did work (there's no clickable 'Compare' and clicking 'diff' says "There are no changes"), it would be significantly better to provide a drop-down option on any commit page -- to compare it with any other commit. – Bob Stein Jan 17 '19 at 20:06
  • 1
    This worked for me. Even with commits on the same branch. +1 – Fibbs Jan 19 '19 at 20:12
  • 1
    we use v5.15.1 and I can't do point 4, because adding either short or long hash does not find anything – Lukas Salich Jul 18 '19 at 14:19
  • Worked for me on current (20190904) bitbucket cloud when entering whole length commit – Si Mon Sep 04 '19 at 14:59
  • 10
    @BobStein I totally agree that bitbucket ux is horrible in this particular situation but I fail to understand how is Alastair Wilkes fault that is like that (unless he implemented it - if that's the case... shame mate... even cli "git diff c1 c2" makes a better job for commits). We should vote the answer not the bitbucket implementation. So I think the -1 is undeserved (+1 to "over"compensate). – zozo Sep 20 '19 at 16:16
  • @zozo I agree with this principle, one should not shoot the messenger. Except in this case the message is misleading as well as disappointing. -1 to &AlastairWilkes for these instructions not working. (I get "There are no changes." when there are.) -5 to bitbucket for bad UX. -10 to Stack Overflow for downvotes being unable to discriminate these nuances. Most of all, I downvoted this answer because it was **not useful** for me (or #ng10 or $LukasSalich). If this answer works for you, by all means upvote it. At best it must be incomplete, needing more steps or restrictions of some kind. – Bob Stein Sep 20 '19 at 18:22
  • This does *not* currently work for me when someone has updated a pull request with "removed 1 commit and added 1 commit". There's no way to see what they actually changed using bitbucket, even though both commits are in the repo. You can ask for the diff between them and it appears to work, but in fact you are only shown the diff between one of them and their common parent. – Jonathan Maddox Feb 12 '21 at 03:27
  • This comparison shows the »tentative merge« that would result if a PR was created for the given revs. I.e. it shows the difference from the merge base to the source, instead of the difference between source and destination. – joki May 12 '21 at 09:16
  • 3
    Does not exist in the current UI anymore. See [joseluisbz's answer](https://stackoverflow.com/a/73314747/242365) for a solution. – cdauth Oct 25 '22 at 21:40
  • Update: Replace "2. Click the '+' menu in the left-nav" with "Click the '...' menu in the left-nav" and it works the same. – Wes Souza May 11 '23 at 12:46
52

This URL worked for me: https://bitbucket.org/<OWNER>/<PROJECT>/branches/compare/<commit1>..<commit2>#diff, short hashes can also be used.

Screenshot:

enter image description here

kambala
  • 2,341
  • 19
  • 20
  • 1
    In April 2020 using the web interface this works as long as you put the commits in the right order (I used the full length sha's but possibly the short ones would work as well). – glaucon Apr 24 '20 at 04:39
  • 2
    Clarification to @glaucon's comment... in the suggested answer, `` and `` represent **source** and **destination** respectively. – Heraldmonkey Oct 14 '20 at 09:22
  • 1
    This just says there are no changes. Maybe it's because it cannot handle comparing 2 commits on the same branch – Alan Macdonald Jul 06 '21 at 12:23
  • @AlanMacdonald just re-tested on nearby commits from one branch: works fine. Updated the answer with screenshot. – kambala Jul 07 '21 at 13:15
  • 8
    I found a defect in bitbucket. If you put the branches in wrong order you see no diff, but crucially the UI has an icon for swapping the order round. When you press it, it visibly changes the commit ids round in order but no diff shows. However if you manually edit the url parameter to swap the order the diff does show. – Alan Macdonald Jul 08 '21 at 09:28
  • 1
    THANK YOU @AlanMacdonald, for the final clarification there! The "switch commits" (arrows) UI control does not work for me, either! And it's very not-intuitive that the commit order depends on having the NEWER commit FIRST. – M.Bearden Sep 30 '22 at 15:53
15

I came across this question while looking for a way to compare a single file across two different commits. The instructions for doing so are slightly different than those above, so I wanted to share:

  1. Browse to the file in question in the "Source" view
  2. Drop down the file's view option and select "Diff":

'Diff' view option

  1. Once the file's diff has loaded, drop down the history options and select the commits that you want to compare between:

Select commits to compare

Scott Carpenter
  • 363
  • 4
  • 4
  • 1
    This comparison shows the »tentative merge« that would result if a PR was created for the given revs. I.e. it shows the difference from the merge base to the source, instead of the difference between source and destination. – joki May 12 '21 at 09:17
12

I found this feature on the BitBucket web GUI.

Arrow to BitBucket Compare feature on Web UI

Instructions:

  1. Click the circles icon on the left toolbar ("Compare" button).
  2. Enter "Source" and "Destination," which are the 2 commits to compare. On the right you can choose what to search for by clicking "Branches," "Tags," or "Commits" over the text box. (You can make different selections for finding Source and Destination, i.e. search for one by tag and the other by commit hash.)

This is an important feature, because it gives you a URL you can share with others.

UPDATE: Others have commented this shows the diff for a resultant merge, so it doesn't work exactly like git diff. I will try to update when I get a chance to experiment with it. I'm not using BitBucket on a day-to-day basis anymore.

reed_do_it
  • 129
  • 1
  • 4
  • thank you! found this as well, only the UI is showing differently to me – ng10 Jun 29 '20 at 17:49
  • 2
    Yes, but this comparison show completely different info comparing to the `git diff` with the same commits ! – socketpair Sep 23 '20 at 06:15
  • 2
    This comparison shows the »tentative merge« that would result if a PR was created for the given revs. I.e. it shows the difference from the merge base to the source, instead of the difference between source and destination. – joki May 12 '21 at 09:15
9

Best way I found to solve this at the time was via SourceTree app (for mac in my case). it will automatically show you the latest changes and you can compare specific commits if you like as well.

Thought I would add this here, as did not find a good answer for this question anywhere. See screenshot showing this functionality

Update, June 29, 2020: Based on answers from reed_do_it and scott-carpenter, went to check this and found that indeed BitBucket now have this feature on the website UI. The version i see on the site, at least for me, is what scott is showing above.

Here is the UI I saw:

  1. On Bitbucket site, go to any repo you have bitbucket repos
  2. Select one of them and click on the file you want to compare select a file in the repo
  3. Click on the Source listbox and select 'Compare' enter image description here
  4. Select the versions you want to compare diff As reed_do_it said, the URL changes with your selection, so you can send someone the link and if they have access to the repo, they can see it as well
ng10
  • 1,660
  • 1
  • 15
  • 19
8

In the Left Pane select Source, then in the three dots select the Compare branches or tags option.

enter image description here

The before action moves to Branches later select respectively the Branch/Tag.

enter image description here

joseluisbz
  • 1,491
  • 1
  • 36
  • 58
6

@kambala's solution is correct but with a simple change. The URL will be encoded and you can't simply use '...'

This url will work

https://bitbucket.org/<OWNER>/<PROJECT>/branches/compare/<COMMIT_1>%0D<COMMIT_2>

targhs
  • 1,477
  • 2
  • 16
  • 29
1

I do it like this under Bitbucket v5.9.0.

  1. Set a tag on the 2 commits you want to compare (hope you have the rights)
  2. Select "Pull Requests" on the left bar
  3. Press the "Create Pull Request" button in the upper right corner
  4. Now you can select the "from" and "to" tags. Do not generate the pull request, just compare the "Diff"

I don't know why this very primitive functionality is not available without having to use some "tricks".

simpleman
  • 19
  • 1