How to compare two commits in BitBucket?

GitBitbucket

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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'

Solution 2 - Git

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

Solution 3 - Git

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

Solution 4 - Git

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.

Solution 5 - Git

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

Solution 6 - Git

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".

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionng10View Question on Stackoverflow
Solution 1 - GitAlastair WilkesView Answer on Stackoverflow
Solution 2 - GitkambalaView Answer on Stackoverflow
Solution 3 - GitScott CarpenterView Answer on Stackoverflow
Solution 4 - Gitreed_do_itView Answer on Stackoverflow
Solution 5 - Gitng10View Answer on Stackoverflow
Solution 6 - GitsimplemanView Answer on Stackoverflow