How can I generate a diff for a single file between two branches in github

Here is my workaround when the following issue applies.

This comparison is big! We’re only showing the most recent 250 commits

Copy the raw view of the file that you want to compare to https://gist.github.com/. Use the two specific commit points that you want to compare. Start with the older commit.

https://gist.github.com/ has a nice side-by-side diff view when you click 'Revisions'.


For people who want to only see (not download) the history/revision of code changes of a file in the GitHub web page:

Go to that file on GitHub, then select History. This will open a page with a list of commit links like below.

Screenshot of a GitHub file history page showing that commit titles and hashes are clickable

On clicking on it, it will show the code changes. After clicking the history, you can click on packages to see package level all files commits.

In Eclipse, you can compare the history using EGit plugin and "Right click ->Compare with" on the file. How can I compare two revisions in git in Eclipse?


GitHub only exposes the way to show diff between two commits.

Provided those tags actually point to commits, the Url format would be something like

https://github.com/{user}/{repository}/compare/{from-tag}...{until-tag}

As an example, https://github.com/libgit2/libgit2sharp/compare/v0.9.0...v0.9.5 shows the diff between two versions of the LibGit2Sharp project. This diff includes all the modified files.

If you want to retrieve a URL that targets a specific file:

  • Switch to the Files Changed tab

changed-tab

  • Click on the Show Diff Stats button (This will display the list of modified files as links)

show-diff

  • Copy to the clipboard the link of the specific file you're after... and Tada! You're done.

For instance, given the diff above, the link https://github.com/libgit2/libgit2sharp/compare/v0.9.0...v0.9.5#diff-11 will point to the LazyFixtures.cs changes that occured between version v0.9.0 and v0.9.5.

Update

Following your comment which states that your diff is too big to be rendered through the Web interface, how about reverting to good old command line tooling? You could redirect the output of the diff to a file and then send the file as an email attachment.

$ git diff v0.9.0 v0.9.5 -- LibGit2Sharp.Tests/LazyFixture.cs > /tmp/lazyfixture.diff

Tags:

Git

Github