How to download a single commit-diff from GitHub?

GithubDiffPatchGit Diff

Github Problem Overview


I would like to get a single commit (let's call it ${SHA}) from GitHub via the web-interface.

For example, something like:

$ git clone http://github.com/foo/bar
$ cd bar
$ git format-patch -o .. ${SHA}~1..${SHA}
$ cd ..
$ rm -rf bar

...but without having to clone the entire repository (the repo in question is large).

Obviously GitHub can display the diff of a given commit via the web interface, but how I can extract that into a (unified) diff-file (ideally, with the commit-message intact)?

Github Solutions


Solution 1 - Github

OK, found the answer myself.

Adding .patch (or .diff) to the commit-URL will give a nice patch:

https://github.com/foo/bar/commit/${SHA}.patch

Thanks to Ten Things You Didn't Know Git And GitHub Could Do...

Solution 2 - Github

I found I had to add a / at the end, i.e.

https://github.com/foo/bar/commit/${SHA}.patch/

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
QuestionumläuteView Question on Stackoverflow
Solution 1 - GithubumläuteView Answer on Stackoverflow
Solution 2 - GithubJanView Answer on Stackoverflow