How to compare two revisions in Bitbucket?
GitBitbucketGit 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!
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)
Solution 7 - Git
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
What worked for me was https://bitbucket.org/-theusername-/-projectnamealllowercase-/branches/compare/-Leftalphanumberic_commitcode-..-Rightalphanumeric_commit-#commits
Replace the -username-
with your username
Thanks to @Aguardientico
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