6

I want to compare "just the file contents" of two branches of a GitHub repository. When I use the default compare view for a pull request for example, it does still show me some diffs, even though the files are identical.

You can reproduce the situation like this:

  1. Create new repository on GitHub with a file README.
  2. Add text to README and push the commit to a new branch duplicate.
  3. Add the same text to README of the master branch.
  4. Both README files from both branches now have identical content, yet https://github.com/user/repo/compare/duplicate shows a diff between duplicate and master.

I know this diff is being shown because the changes to both files have been introduced by different commits, but sometimes it's more useful to only see the differing file contents, i. e. what would really get changed by merging. In the example above, master wouldn't change at all.

As far as I understand, the git CLI command provides this feature for local folders with its --no-index option. So, I could clone the two branches to my local file system and compare them with git diff --no-index. How can I achieve this without having to clone them first? I want to view the difference online on GitHub.


Update: I don't think the issue has anything to do with the --no-index option. If I download the repository and use git diff locally, I noticed the following: git diff master..duplicate (two dots) won't show a difference and git diff master...duplicate (three dots) will show the same as GitHub's compare online.

Therefore, this question is similar to this one: Github Comparison View for 2 branches is incorrect?

In short: Currently, GitHub's compare view always uses git diff with three dots. More information about the difference between two and three dots also at https://git-scm.com/docs/git-diff

finefoot
  • 9,914
  • 7
  • 59
  • 102
  • 1
    Possible duplicate of [Github/compare: How to diff two different files (different file names, both in HEAD)?](https://stackoverflow.com/questions/30555608/github-compare-how-to-diff-two-different-files-different-file-names-both-in-h) – Schwern Dec 11 '17 at 20:29
  • 1
    You can also do a shallow clone with `git clone --depth 1`. This avoids downloading the whole history, it will just get the latest commit on `master`. The savings in download time depend on the history of the repository. Most repositories are very small, and Git is very difficult to work with without cloning a working copy. – Schwern Dec 11 '17 at 20:31
  • What do you mean identical? There's clearly a dummy edit at the bottom of the file in the duplicate branch. – Lasse V. Karlsen Jan 28 '18 at 15:22
  • Perhaps it is only showing the changes introduced on that branch? I haven't used the comparison feature of github but I agree, this looks odd. – Lasse V. Karlsen Jan 28 '18 at 15:31
  • 1
    You now (Sept. 2018) can compare "just the files" of two branches of a GitHub repository. See [my answer below](https://stackoverflow.com/a/52487289/6309). – VonC Sep 24 '18 at 21:03

2 Answers2

2

As it's a GitHub repository:

https://github.com/{USER_OR_ORG}/{REPOSITORY}/compare/{BRANCH_1}...{BRANCH_2}.patch

(You can remove the '.patch' to see the difference in GitHub UI)

msanford
  • 11,803
  • 11
  • 66
  • 93
zigarn
  • 10,892
  • 2
  • 31
  • 45
1

This is now (Sept. 2018) supported.
See "Dos dots, the two dot commit comparison"

This creates the ability to do a direct “two dot” comparison between two commits.
Now you can easily see the differences between two commits without comparing from their common merge base commit like a three dot comparison would.

See "Three-dot and two-dot Git diff comparisons".
For example:

https://github.com/github/linguist/compare/c3a414e..faf7c6

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250