How to download a single commit-diff from GitHub?

59,528

Solution 1

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

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

https://github.com/foo/bar/commit/${SHA}.patch/
Share:
59,528
umläute
Author by

umläute

media-artist, open-source developer, system administrator and phd-student (phew!)

Updated on July 08, 2022

Comments

  • umläute
    umläute almost 2 years

    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)?

  • umläute
    umläute over 5 years
    as of today, I'm unable to reproduce this: github.com/torvalds/linux/commit/… (without trailing slash) works fine for me (tested with firefox, cURL and wget)
  • Darshan L
    Darshan L over 3 years
    can we directly use this url in the git apply command? like git apply <url.diff>
  • umläute
    umläute over 3 years
    @DarshanL well that is a completely different question about the powers of the git cmdline tool (and super simple to try out ;-)) and unrelated to github (github would just be a provider of such a file; but any patch file served over http:// would do) - however the short answer is probably: no
  • baptx
    baptx about 3 years
    Is there also an easy way to get the patch if it is done in several commits? (instead of downloading and applying several patches)
  • PF4Public
    PF4Public over 2 years
    If you get Content containing PDF or PS header bytes cannot be rendered from this domain for security reasons. with .patch, try .diff. It worked for me.
  • Wenod Pathirana
    Wenod Pathirana about 2 years
    If you have binary files in your commit or PR, use .patch instead of .diff.