How can I download the changes contained in a Github pull request as a unified diff?

up vote 393 down vote accepted

To view a commit as a diff/patch file, just add .diff or .patch to the end of the URL, for example:

  • 11
    Great, thanks. And there is also .patch. Why is this not exposed in the GUI? How is one supposed to discover this? – Thilo May 31 '11 at 14:04
  • 37
    It's not documented to keep stackoverflow in business. Honestly, that is FAQ #2 – sehe May 31 '11 at 14:15
  • Also because git pull is the preferred method of downloading and applying the changes. – Tekkub Jun 1 '11 at 5:20
  • 14
    Also see github.com/blog/967-github-secrets – Davi Lima May 7 '13 at 14:25
  • 3
    Judging by what these return and the the links in the docs at developer.github.com/v3/media/… , the .diff URL gives a straight diff to the default branch based on git-diff git-scm.com/docs/git-diff output, and the .patch URL gives a concatenation of the individual commits in the PR (each relative to their parent commit) in a format suitable for e-mailing based on git-format-patch git-scm.com/docs/git-format-patch output. – rakslice May 7 '17 at 0:10

Somewhat related, to let git download pull request 123 and patch it into mylocalbranch locally, run:

git checkout -b mylocalbranch
git pull origin pull/921/head
  • 10
    Or to get the pull request onto a new PR branch git fetch origin pull/921/head:PR and then merge with your current branch, giving you a chance to review the changes git merge PR --no-commit --no-ff – MoonStom Mar 4 '15 at 21:08
  • 3
    The full documentation is at help.github.com/articles/checking-out-pull-requests-locally – JBert Feb 23 '16 at 11:22
  • This requires you to setup Git with your credentials. You cannot anonymously test a proposed change (like you could by apply a diff manually). Yet another instance of Git taking a simple workflow and making it difficult. – jww Mar 23 '17 at 18:39

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.