How can I download the changes contained in a Github pull reques开发者_如何学Pythont as a unified diff?
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
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
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
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
精彩评论