How can I fetch an unmerged pull request for a branch I don't own?

I need to pull in a specific pull request (that hasn't been processed into the main stream yet) in the NServiceBus repo:

https://github.com/johnsimons/NServiceBus/commit/d8524d53094e8181716e771c1023e968132abc15

It's obviously not my repo, but I need the changes that exist in that pull request.

What is the best way to do this?


To fetch a pull into your repository:

git fetch git@github.com:jboss/jboss-common-beans.git refs/pull/4/head

Then do whatever you want with FETCH_HEAD:

git checkout -b new-branch FETCH_HEAD

git pull origin pull/28/head

Or

git fetch origin pull/28/head:28
git checkout 28

Can I pull a not-yet-merged pull request?


You can do this:

1) Add the upstream remote:

git remote add upstream git@github.com:Particular/NServiceBus.git

2) After that, you can checkout any pull request to a new branch per its ID:

git fetch upstream pull/PULL_REQUEST_ID/head:NEW_BRANCH_NAME

Then you'll have a branch named NEW_BRANCH_NAME containing the PR code.

Adding an alias:

If you do this as often as me, you may want to setup some aliases for it. I have this in my .gitconfig:

[alias]
    fetch-pr = "!f(){
        [ -z "$1" ] && { echo Usage: git fetch-pr PULL_REQUEST_ID [REMOTE_NAME] [NEW_BRANCH_NAME]; exit 1; }; 
        remote=${2:-origin}; 
        branch=${3:-pr-$1}; 
        git fetch $remote "pull/$1/head:$branch"; 
        }; f "
    pr = "!f(){
        branch=${3:-pr-$1}; 
        git fetch-pr "$@"; 
        git switch $branch; 
        }; f "

With the above, I can do:

git fetch-pr 123              # fetch PR #123 into branch pr-123
git fetch-pr 123 some-branch  # fetch PR #123 into some-branch
git pr 123                    # fetch and switch to the branch
链接地址: http://www.djcxy.com/p/22456.html

上一篇: GitHub克隆从拉请求?

下一篇: 我如何获取我没有的分支的未合并拉取请求?