GitHub上的一个项目,我有一个fork,它有一个新的pull请求,我想把它拉到我的fork中,但作者还没有拉进去。

有一个简单的方法来应用从其他叉子的拉请求到我的叉子?这里还有什么我没注意到的吗?


当前回答

你可以很容易地手动完成:

add the other fork as a remote of your repo: git remote add otherfork git://github.com/request-author/project.git fetch his repo's commits git fetch otherfork You have then two options to apply the pull request (if you don't want to choose pick 1.) If you don't care about applying also the eventual commits that have been added between the origin and the pull request, you can just rebase the branch on which the pull request was formed git rebase master otherfork/pullrequest-branch If you only want the commits in the pull request, identify their SHA1 and do git cherry-pick <first-SHA1> <second-SHA1> <etc.>

其他回答

为此,我使用了一个方便的脚本。我运行脚本输入:

git prfetch upstream

它从上游fork获得所有的pull请求。

要创建脚本,创建一个文件~/bin/git-prfetch。

该文件应包含以下内容:

#!/bin/bash

if [ -z "$1" ]; then
    echo "Please supply the name of a remote to get pull requests from."
    exit 1
fi

git fetch $1 +refs/heads/\*:refs/remotes/$1/\* +refs/pull/\*/head:refs/remotes/$1/pr/\*

通过设置,确保你的路径包含脚本:

export PATH="$HOME/bin:$PATH"

您可以将该文件添加到~/。Bashrc使这一变化永久化。

现在,确保你添加了你想要获得pull请求的fork:

git remote add upstream https://github.com/user/repo.git

然后

git prfetch upstream

我会这样做;

git checkout master
git remote add #NAME# #ADDRESS TO REPO#
git fetch #USERNAME#
git checkout -b test_fork
git rebase #NAME#/#BRANCH#

现在,我已经将更改合并到一个名为test_fork的测试分支中。这样任何改变都不会弄脏树。

如果更可取的话,还可以像上面描述的那样使用cherry-pick来选择特定的提交。

快乐旅行:)

一些对我有用的更详细的信息。

我的.git/配置文件分叉回购看起来像这样:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = false
[remote "origin"]
        url = git@github.com:litzinger/angular-carousel.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
        rebase = true
[remote "source"]
        url = git://github.com/revolunet/angular-carousel.git
        fetch = +refs/heads/*:refs/remotes/source/*
        fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

然后运行“git fetch source”,然后列出来自fork repo的所有拉请求。

 * [new ref]         refs/pull/54/head -> origin/pr/54
 * [new ref]         refs/pull/67/head -> origin/pr/67
 * [new ref]         refs/pull/69/head -> origin/pr/69
 * [new ref]         refs/pull/71/head -> origin/pr/71

然后在一个特定的pull请求中合并运行"git merge master origin/pr/67"

你可以很容易地手动完成:

add the other fork as a remote of your repo: git remote add otherfork git://github.com/request-author/project.git fetch his repo's commits git fetch otherfork You have then two options to apply the pull request (if you don't want to choose pick 1.) If you don't care about applying also the eventual commits that have been added between the origin and the pull request, you can just rebase the branch on which the pull request was formed git rebase master otherfork/pullrequest-branch If you only want the commits in the pull request, identify their SHA1 and do git cherry-pick <first-SHA1> <second-SHA1> <etc.>

就像Tekkub之前说的,你可以直接把分支拉进去。在GitHub的大多数情况下,分支只是请求用户的项目分支的“主”。

示例:git拉https://github.com/USER/PROJECT/ BRANCH

举个实际的例子:

假设你fork了一个名为safaribooks的github项目,在初始项目中有以下拉请求,你想把它放在你的fork中:

然后,在fork的克隆项目文件夹中,运行:

git pull https://github.com/fermionic/safaribooks.git fix-str-decode