How to compare two revisions in Bitbucket?

GitBitbucket

Git Problem Overview


My team is using Bitbucket for our git repository and we've recently starting using the pull request functionality for code reviews. It works fine on the first review, but if it goes through multiple iterations (that is, changes are made and pull request updated), I would like to see a link with just the new changes that were made since the last code review.

I looked into the "compare" functionality but the UI looks like it can only compare between branches. Is there a simple way to get a diff between two commits?

Git Solutions


Solution 1 - Git

This is just a slight modification to the answers already given but adding #diff to the end instead of #commits is usually what I'm looking for. Also as others may have mentioned the best results for me are usually obtained by placing the newer commit first and the older one second but that will depend on your particular needs.

https://bitbucket.org/<OWNER>/<REPO>/branches/compare/<commit-hash>..<commit-hash-older>#diff

Solution 2 - Git

The search fields in the branch/tag dropdowns on the Compare page on bitbucket.org now supports pasted-in commit hashes.

So now you can just go to https://bitbucket.org/<owner>/<repo>/branches/compare/ and paste the hashes into the dropdowns instead of URL hacking!

drop down, then paste in commit hash

Solution 3 - Git

Try something like:

https://bitbucket.org/<OWNER>/<PROJECT>/branches/compare/<commit1>..<commit2>#commits

Taken from: https://bitbucket.org/site/master/issue/4779/ability-to-diff-between-any-two-commits

Solution 4 - Git

Bitbucket supports comparing tags now.

https://bitbucket.org/<OWNER>/<PROJECT>/branches/compare/<tag1>%0D<tag2>

Solution 5 - Git

I have Bitbucket Server, version:v4.4.1

The answer with me was this.

http://<path-to-my-server>/projects/<project-name>/repos/<repo-name>/commits/<old>?to=<new>

I was looking for this answer because in my project we use git submodules, and in pull requests I can only see the old commit sha vs the new commit sha of each submodule that changed. There is no link to click or anything (that I know of) to jump to this diff view. This url allows me to view what changed in submodules too.

Btw, if someone knows of a better way of comparing two commits in submodules during a pull request, please let me know.

Solution 6 - Git

The Bitbucket compare view format is following:

https://bitbucket.org/<owner>/<repo>/branches/compare/<new>%0D<old>

Given an example ged/ruby-pg (RubyGem, a ruby library):

To compare two releases (from v0.18.1 to v0.18.2)

https://bitbucket.org/ged/ruby-pg/branches/compare/v0.18.2%0Dv0.18.1

To compare two revisions (from f97dd6c to 22a3612)

https://bitbucket.org/ged/ruby-pg/branches/compare/22a361201fd1d387d59a066b179124694a446f38%0Df97dd6cb4f34da6a62c4339887249115c7c25b9c

Solution 7 - Git

GO to your bitbucket repository > Branches enter image description here

Click on the menu icon and on compare

Solution 8 - Git

You can also do this inside of a pull request, say after someone makes a push to a branch to fix review findings. To my knowledge there's no UI for this yet, but you can enter the url like this:

https://<bitbucket-server>/projects/<PROJECT>/repos/<REPO>/pull-requests/<PR-NUM>/<commit-hash>?since=<commit-hash-older>

Solution 9 - Git

Solution 10 - Git

Create a light tag to the commit(s) you want to compare. git -a [tagname] [commit_sha]

Then in Bitbucket, in the compare menu (the one to do pull requests) simply compare with tags.

Solution 11 - Git

At the command prompt

git log -p -1

>This shows the comparison with the previous version.

git log -p -5 > This shows the last 5 revisions, comparing two successive versions (n & n-1, n-1 & n-2, etc).

I realize, this is not ideal to show direct difference between two specific versions.

Ref. https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History

Solution 12 - Git

Via terminal, run git on your project path:

git diff <new commit> <old commit>

Ex: git diff 26cf60f be5f978

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
Questionbrian.kengView Question on Stackoverflow
Solution 1 - GitNight OwlView Answer on Stackoverflow
Solution 2 - GitAlastair WilkesView Answer on Stackoverflow
Solution 3 - GitAguardienticoView Answer on Stackoverflow
Solution 4 - GitTaoView Answer on Stackoverflow
Solution 5 - Gitsantiago ariztiView Answer on Stackoverflow
Solution 6 - GitJuanito FatasView Answer on Stackoverflow
Solution 7 - GitHarsh PhoujdarView Answer on Stackoverflow
Solution 8 - GitIsaac BakerView Answer on Stackoverflow
Solution 9 - GitSiddharthView Answer on Stackoverflow
Solution 10 - GitCyrille CormierView Answer on Stackoverflow
Solution 11 - GitAnirudha SinghView Answer on Stackoverflow
Solution 12 - GitRaul B SantosView Answer on Stackoverflow