Download Github pull request as unified diff
75,268
Solution 1
To view a commit as a diff/patch file, just add .diff
or .patch
to the end of the URL, for example:
- https://github.com/weppos/whois/pull/90
- https://github.com/weppos/whois/pull/90.diff
- https://github.com/weppos/whois/pull/90.patch
Solution 2
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
Solution 3
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
Author by
hansvb
Updated on July 08, 2022Comments
-
hansvb almost 2 years
How can I download the changes contained in a Github pull request as a unified diff?
-
hansvb about 13 yearsGreat, thanks. And there is also
.patch
. Why is this not exposed in the GUI? How is one supposed to discover this? -
sehe about 13 yearsIt's not documented to keep stackoverflow in business. Honestly, that is FAQ #2
-
Tekkub about 13 yearsAlso because
git pull
is the preferred method of downloading and applying the changes. -
mirabilos over 10 yearsOoooh, 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.
-
Cory Trese over 10 yearsThank you so much. This is very useful for porting changes from Github into SVN or whatever repo you have. They all accept diff and patch, so this is a great way to make changes more portable. Thanks!
-
Rohit Choudhary over 9 yearsbut how to ignore prefixes? a and b coming before file paths
-
MoonStom about 9 yearsOr 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
-
JBert over 8 yearsThe full documentation is at help.github.com/articles/checking-out-pull-requests-locally
-
jww about 7 yearsThis 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.
-
rakslice about 7 yearsJudging 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. -
ivan_pozdeev over 6 years@RohitKumarChoudhary use
-p1
withpatch
. -
Mandar Vaze over 4 yearsI reached here via a google search, and few hours later, I noticed that github now shows this as a "ProTip" below each PR
-
cambunctious over 3 yearsApply the PR commits to your repo in one line:
curl <patch url> | git am