git 如何将来自其他分叉的未合并的上游拉取请求应用到我的分叉中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6022302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:56:45  来源:igfitidea点击:

How to apply unmerged upstream pull requests from other forks into my fork?

gitgithubpull-request

提问by leek

A project on GitHub that I have a fork of has a new pull requests that I want to pull into my fork that the author has not pulled in yet.

我在 GitHub 上有一个分支的项目有一个新的拉取请求,我想拉入我的分支,作者尚未拉入。

Is there a simple way to apply pull request from other forks into my fork? Is there something else here that I am missing?

有没有一种简单的方法可以将来自其他分叉的拉取请求应用到我的分叉中?这里还有什么我想念的吗?

采纳答案by CharlesB

You can do it manually quite easily:

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

  • 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.)

    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
      
    2. If you only want the commits in the pull request, identify their SHA1 and do

      git cherry-pick <first-SHA1> <second-SHA1> <etc.>
      
  • 添加另一个 fork 作为你的 repo 的远程:

    git remote add otherfork git://github.com/request-author/project.git
    
  • 获取他的 repo 的提交

    git fetch otherfork
    
  • 然后您有两个选项来应用拉取请求(如果您不想选择选择 1。)

    1. 如果您不关心应用在原点和拉取请求之间添加的最终提交,您可以重新建立拉取请求所在的分支

      git rebase master otherfork/pullrequest-branch
      
    2. 如果您只想要拉取请求中的提交,请确定它们的 SHA1 并执行

      git cherry-pick <first-SHA1> <second-SHA1> <etc.>
      

回答by Hotschke

Update: Via Webpage

更新:通过网页

You can also do this via the github webpage.

您也可以通过 github 网页执行此操作。

I assume, you should have already a fork (MyFork) of the common repo (BaseRepo) which has the pending pull request from a fork (OtherFork) you are interested in.

我假设,您应该已经有一个MyFork公共 repo ( BaseRepo)的 fork ( ),其中包含来自OtherFork您感兴趣的 fork ( )的挂起拉取请求。

  1. Navigate to the fork (OtherFork) which has initiated the pull request which you like to get into your fork (MyFork)
  2. Go to the pull requests page of OtherFork
  3. Click new pull request
  4. The pending pull request(s) should be offered. Remember to select proper OtherForkbranch too. Select on the left side as the base fork your fork (MyFork) (IMPORTANT).
  5. Now the option of View pull requestshould change to Create pull request. Click this.
  1. 导航到OtherFork已经发起拉取请求的 fork ( ),你想进入你的 fork ( MyFork)
  2. 转到拉取请求页面 OtherFork
  3. 点击新的拉取请求
  4. 应提供挂起的拉取请求。记住也要选择合适的OtherFork分支。选择左侧作为您的前叉 ( MyFork) (重要信息)的基础叉。
  5. 现在 的选项View pull request应该更改为Create pull request。点击这个。

Now you should have a pending pull request in your fork (MyFork), which you can simply accept.

现在您的 fork ( MyFork) 中应该有一个待处理的拉取请求,您可以简单地接受它。

回答by SciPhi

Like Tekkub said previously, you can just pull the branch in directly. Most of the time with GitHub, the branch is simply "master" on the requesting User's fork of the project.

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

Example: git pull https://github.com/USER/PROJECT/ BRANCH

例子: git pull https://github.com/USER/PROJECT/ BRANCH

And as a pratical example:

作为一个实际的例子:

Say you forked a github project called safaribooks and there is the following pull request, in the originating project, that you want to put in your fork:

假设您分叉了一个名为 safaribooks 的 github 项目,并且在原始项目中有以下拉取请求,您希望将其放入您的分叉中:

enter image description here

在此处输入图片说明

Then, in your fork's cloned project folder, run:

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

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

回答by jbyler

Pull requests for the project may come from many different authors (forks), and you probably don't want a separate remote for each fork. Also, you don't want to make any assumptions about the branch the author used when submitting the pull request, or what else might be in the author's master branch. So it's better to reference the pull request as it appears in the upstream repository, rather than as it appears in the other forks.

项目的拉取请求可能来自许多不同的作者(分叉),您可能不希望每个分叉都有一个单独的遥控器。此外,您不希望对作者在提交拉取请求时使用的分支做出任何假设,或者作者的主分支中可能还有什么。因此,最好在上游存储库中引用拉取请求,而不是在其他分支中引用它。

Step 1:

第1步:

git remote add upstream <url>

You've probably already done this step, but if not, you'll want a remote defined for the upstream project. The URL is the clone URL of the project you forked. More info at Configuring a remote for a forkand Syncing a fork. upstreamis the name you are giving to the remote, and while it can be anything, upstreamis the conventional name.

您可能已经完成了这一步,但如果没有,您将需要为上游项目定义一个远程。URL 是您分叉的项目的克隆 URL。更多信息请参见为叉子配置遥控器同步叉子upstream是您为遥控器取的名称,虽然它可以是任何upstream名称,但它 是常规名称。

Step 2:

第2步:

git pull upstream refs/pull/{id}/head

... where {id}is the pull request number. upstreamis the name of the remote to pull from, i.e. just "upstream" if you followed step 1 exactly. It can also be a URL, in which case you can skip step 1.

...{id}拉取请求编号在哪里。 upstream是要从中拉出的遥控器的名称,即如果您完全按照第 1 步操作,则只是“上游”。它也可以是 URL,在这种情况下,您可以跳过步骤 1。

Step 3:

第 3 步:

Type in a commit message for the merge commit. You can keep the default, although I recommend giving a nice one-line summary with the pull request number, the issue it fixes, and a short description:

为合并提交输入提交消息。您可以保留默认值,但我建议使用拉取请求编号、它修复的问题和简短描述提供一个很好的单行摘要:

Merge PR#42, fixing VIM-652, support for mapping arbitrary IDEA actions

回答by Brian Litzinger

Some more detailed info that worked for me.

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

My .git/config file for the forked repo looks like this:

我的分叉仓库的 .git/config 文件如下所示:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = false
[remote "origin"]
        url = [email protected]: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/*

Then run "git fetch source", which then listed all the pull requests from the forked repo.

然后运行“git fetch source”,然后列出来自分叉仓库的所有拉取请求。

 * [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

And then to merge in a specific pull request run "git merge master origin/pr/67"

然后在特定的拉取请求中合并运行“git merge master origin/pr/67”

回答by MindTooth

What I would do is the following;

我会做的是以下;

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

I have now merged the changes into a test branch, named test_fork. So that any changes won't dirty my tree.

我现在已将更改合并到一个名为test_fork. 这样任何更改都不会弄脏我的树。

Optionally you can use cherry-pick as described above to pick a particular commit if that is more preferable.

如果更可取,您可以选择使用如上所述的cherry-pick来选择特定的提交。

Happy travels :)

旅途愉快 :)

回答by Richard

I use a handy dandy script for this. I run the script by typing:

为此,我使用了一个方便的花花公子脚本。我通过键入以下内容运行脚本:

git prfetch upstream

and it gets all of the pull requests from the upstream fork.

它从上游分支获取所有拉取请求。

To create the script make a file ~/bin/git-prfetch.

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

The file should contain the following:

该文件应包含以下内容:

#!/bin/bash

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

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

Ensure that your path includes the script by setting:

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

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

You can add this file to ~/.bashrcto make the change permanent.

您可以将此文件添加到~/.bashrc以使更改永久化。

Now, make sure you add the fork you want to get the pull requests from:

现在,确保添加要从中获取拉取请求的分叉:

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

And then

进而

git prfetch upstream