如何在 git 中合并其他人项目的拉取请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5553156/
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:33:03  来源:igfitidea点击:

How do I merge a pull request on someone else's project in git?

gitgithubpull-request

提问by DisgruntledGoat

I cloned this repo on my computer: https://github.com/derobins/wmd.git

我在我的电脑上克隆了这个 repo:https: //github.com/derobins/wmd.git

There are several bugs with it though, and it looks like another user has fixed them and issued "Pull requests" (I assume these are requests for their changes to be committed?)

但是它有几个错误,看起来另一个用户已经修复了它们并发出了“拉取请求”(我认为这些是提交更改的请求?)

Is it possible to merge those changes into my local version?

是否可以将这些更改合并到我的本地版本中?

EDIT: just to be clear, this is notmy repository. I am using the WMD editor from derobins, but it has several bugs which those pull requests purport to fix. I have cloned the repo on Ubuntu (not in github) and was hoping to merge those changes in if possible.

编辑:只是要清楚,这不是我的存储库。我正在使用来自 derobins 的 WMD 编辑器,但它有几个错误,这些拉取请求声称要修复这些错误。我已经在 Ubuntu(不在 github 中)克隆了这个 repo,并希望在可能的情况下合并这些更改。

回答by Mark Longair

(GitHub has very thorough documentationon how to deal with pull requests.)

(GitHub 有关于如何处理拉取请求的非常详尽的文档。)

Essentially, you'll want to add a remote for the repository of the person who made the pull requests, e.g.:

本质上,您需要为发出拉取请求的人的存储库添加一个远程,例如:

git remote add helpful git://github.com/helpful-person/whatever.git

... then fetch their changes into remote-tracking branches:

...然后将他们的更改提取到远程跟踪分支中:

git fetch helpful

... so that now you have all the commits from that person's GitHub repository in your clone of the upstream repository. If you look at the additional commits within that pull request you could:

...这样现在您在上游存储库的克隆中拥有来自该人的 GitHub 存储库的所有提交。如果您查看该拉取请求中的其他提交,您可以:

  1. merge the latest one, e.g. git merge 75708aeab5
  2. cherry pick each of those changes, e.g. git cherry-pick 2142db89, git cherry-pick 75708aeab5
  3. create a local branch to work on them further, e.g. git checkout -b fix-for-issue3 75708aeab5
  4. etc. etc.
  1. 合并最新的,例如 git merge 75708aeab5
  2. 樱桃挑选每一个变化,例如git cherry-pick 2142db89git cherry-pick 75708aeab5
  3. 创建一个本地分支以进一步处理它们,例如 git checkout -b fix-for-issue3 75708aeab5
  4. 等等等等

An alternative is to just clone the repository of the contributor who made the pull requests instead, if that's the same but for those fixes.

另一种方法是克隆提出拉取请求的贡献者的存储库,如果相同但对于这些修复程序。

回答by Andrew-Dufresne

The accepted answer suggests to clone or add remote for the repository of the person who made the pull request. Another cleaner and simpler wayis to use this command

接受的答案建议为发出拉取请求的人的存储库克隆或添加远程。另一种更简洁更简单的方法是使用这个命令

git pull https://github.com/otheruser/repo.git branchname

For example, at the time of writing, ghihas three open pull requests that haven't been merged yet. This is what I did to merge them into my local repo.

例如,在撰写本文时,ghi有三个尚未合并的开放拉取请求。这就是我为将它们合并到我的本地仓库所做的工作。

# I want to make sure my master is in sync with the upstream master
git checkout -b merge-patches master
# first pull request
git pull --no-ff https://github.com/TiddoLangerak/ghi.git master
# second pull request
git pull --no-ff https://github.com/wayfare/ghi.git master

Note that both pull requests were sent from master that is why I pulled from their masterbranch.

请注意,两个拉取请求都是从 master 发送的,这就是我从他们的master分支拉取的原因。

This way, other repositories do not get added to your remotes, neither you have to cherry pick or clone them locally.

这样,其他存储库不会添加到您的遥控器中,您也不必在本地挑选或克隆它们。

回答by kalkin

You clone the repo to you github account. Then just visit the forkqueue of your cloned repo and choose the patches you want to merge in to your repository.

您将 repo 克隆到您的 github 帐户。然后只需访问克隆存储库的 forkqueue 并选择要合并到存储库中的补丁。