Reputation: 262464
How can I download the changes contained in a Github pull request as a unified diff?
Upvotes: 390
Views: 112156
Reputation: 1169
There is another alternative to the related solution. It answers the original question and uses git fetch
and FETCH_HEAD
.
git fetch origin pull/921/head
cat .git/FETCH_HEAD
# Then either of
git diff `git merge-base FETCH_HEAD HEAD`..FETCH_HEAD > diff.diff # Downloads the unified diff as asked in the original question
git merge FETCH_HEAD # Applies the diff
Upvotes: 0
Reputation: 2374
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
Upvotes: 6
Reputation: 176352
To view a commit as a diff/patch file, just add .diff
or .patch
to the end of the URL, for example:
Upvotes: 715
Reputation: 5889
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
Upvotes: 63