How to compare two different commits on the same branch in github?

You can use the following URL structure to compare commits in the same branch:

github.com/<username>/<repo_name>/compare/<commit1>...<commit2>

Replace values for username, repo_name, commit1(old commit) & commit2(new commit) acc. to your project.

The separator between the two commits is ... i.e. 3 dots.


TLDR: Just add /compare at the end of the URL.

You can use the Github Compare UI, which will generate the URL for you. Replace ORG and REPO with your values. The UI only lists branches, but you can also type in any valid Tags (e.g. v1.0.0) or Commit IDs (e.g. 1a2b3c).

https://github.com/ORG/REPO/compare/

GitHub GUI showing compare options


The URLs that get generated are in this format. You can also manually edit the URL with the REFs.

https://github.com/ORG/REPO/compare/REF1...REF2

You can also use "2 dots" (direct diff) instead of "3 dots" (diff from last common commit). Same as git diff A..B vs git diff A...B.

https://github.com/ORG/REPO/compare/REF1..REF2

If you want to compare across forks, then you need to add ORG2:

https://github.com/ORG/REPO/compare/REF1...ORG2:REF2

There is documentation, but I didn't think it was that clear: https://help.github.com/en/github/committing-changes-to-your-project/comparing-commits-across-time


to see the difference between branches or tags

(branches if no pull request has been made)

  • https://github.com/PyCQA/mccabe/compare/bug/39...master (diff between two branches bug/39and master)
  • https://github.com/PyCQA/mccabe/compare/0.6.0...0.6.1 (diff between two tags)
  • https://github.com/PyCQA/mccabe/compare/0.6.1...master (diff between tag and master)

Notes:

  • (if a pull request has been made you can see the changes inside the PR, no longer via the compare url)

  • You can use the dropdowns to select different branches or tags: enter image description here

  • take care of the order, eg. https://github.com/PyCQA/mccabe/compare/master...0.6.1 will give no results

  • you can choose between 2-dot (..) or 3-dot (...) notation

to see the difference between commits:

  • https://github.com/PyCQA/mccabe/compare/55942cb...HEAD

  • https://github.com/PyCQA/mccabe/compare/55942cb...e92e9e7


The article you linked has instructions for comparing commits.

The GitHub comparison tool will accept any revision. Branches, tags, commit IDs, even dates. If you want to compare between two commits, give it the commit IDs. Here's their example.

Tags:

Git

Github