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

我需要在NServiceBus回购中引入特定的拉取请求(尚未处理到主流中):

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

这显然不是我的回购,但我需要该拉取请求中存在的更改。

做这个的最好方式是什么?


要抓取您的存储库:

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

然后用FETCH_HEAD做任何你想做的事情:

git checkout -b new-branch FETCH_HEAD

git pull origin pull/28/head

要么

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

我可以拉一个尚未合并的拉请求吗?


你可以这样做:

1)添加上游远程:

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

2)之后,您可以通过其ID来检出对新分支的任何请求。

git fetch upstream pull/PULL_REQUEST_ID/head:NEW_BRANCH_NAME

然后,您将拥有一个名为NEW_BRANCH_NAME的分支,其中包含PR代码。

添加别名:

如果你经常这样做,你可能需要为它设置一些别名。 我有这在我的.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 "

通过以上,我可以做到:

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/22455.html

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

下一篇: How to commit my current changes to a different branch in git