How can I download the changes contained in a Github pull request as a unified diff?
-
Normally the PR patch link is sent to the person, who's accepting the PR.– kenorbJun 21, 2013 at 9:15
-
This isn't implemented in GitLab yet, but I created a feature request so please add your votes to it.– colanNov 19, 2014 at 16:01
-
cf. the the last ¶ of Pro Git §6.3.3: "Managing Pull Requests: Email Notifications"– GeremiaMar 6, 2017 at 14:40
3 Answers
To view a commit as a diff/patch file, just add .diff
or .patch
to the end of the URL, for example:
-
21Great, thanks. And there is also
.patch
. Why is this not exposed in the GUI? How is one supposed to discover this?– ThiloMay 31, 2011 at 14:04 -
61It's not documented to keep stackoverflow in business. Honestly, that is FAQ #2– seheMay 31, 2011 at 14:15
-
1Ooooh, thanks, this answer is worth gold. (That blogposting too.) I wonder how anyone sane can work without that, and why it is not exposed in the crappy-enough-as-is Web UI. Sep 1, 2013 at 19:43
-
11Judging 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 ongit-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 ongit-format-patch
git-scm.com/docs/git-format-patch output.– raksliceMay 7, 2017 at 0:10 -
1
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
-
10Or 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 changesgit merge PR --no-commit --no-ff
– MoonStomMar 4, 2015 at 21:08 -
5The full documentation is at help.github.com/articles/checking-out-pull-requests-locally– JBertFeb 23, 2016 at 11:22
-
1This 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.– jwwMar 23, 2017 at 18:39
To get the PR changes into your local repo in an staged but uncommitted state, so you can review:
git pull origin pull/123/head --no-commit
And to generate a patch file from that:
git diff --cached > pr123.diff