git 如何在 GitHub 上打开多个拉取请求

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

How to open multiple pull requests on GitHub

gitgithubpull-request

提问by torourke

When I open a pull requeston GitHub.
All commits since my last request and all new ones are automatically added to this request.

当我在GitHub 上打开拉取请求时。 自上次请求以来的所有提交和所有新提交都自动添加到此请求中

I can't seem to control which commits are added and which are not.
When I try to open another pull request, I get an "Oops! There's already a pull request" error.

我似乎无法控制添加哪些提交,哪些没有。
当我尝试打开另一个拉取请求时,我收到“糟糕!已经有拉取请求”错误。

Is there any easy way to open multiple pull requests without having to mess around with the command line?

有没有什么简单的方法可以打开多个拉取请求而不必弄乱命令行?

回答by mipadi

Pull requestsare based on a branch.
The only way to open up a pull request for multiple commits is:

拉取请求基于一个分支。
为多个提交打开拉取请求的唯一方法是:

  1. Isolate them into their own branch.
  2. Open the pull requests from there.
  1. 将它们隔离到自己的分支中
  2. 从那里打开拉取请求。

回答by Tyler Rick

The easiest way I've found to do this is with the hub command (https://github.com/defunkt/hub).

我发现最简单的方法是使用 hub 命令 ( https://github.com/defunkt/hub)。

From your topic branch ("feature" in this example) that you want to create a pull request for, you can just run:

从您要为其创建拉取请求的主题分支(在本例中为“功能”),您只需运行:

git pull-request

(remember to push your branch first!)

(记得先推送你的分支!)

And it will open a new pull request on GitHub for "YOUR_USER:feature".

它将在 GitHub 上为“YOUR_USER:feature”打开一个新的拉取请求。

If you've already created an issue on GitHub, you can even attach a pull request to that existing issue (something you can't do from the web UI):

如果您已经在 GitHub 上创建了一个问题,您甚至可以将拉取请求附加到该现有问题(这是您无法从 Web UI 执行的操作):

$ git pull-request -i 123
[ attached pull request to issue #123 ]

回答by Riking

You actually CAN do this without creating another branch, but it takes a bit of playing around.
Here's the steps:

您实际上可以在不创建另一个分支的情况下执行此操作,但这需要一些操作。
以下是步骤:

  1. Identify the two commit ranges you want to pull. Here's what i'll use for an example:
    (other/master) A -> B -> C -> D -> E (yours/master)
    Let's say that you want to pull B and C in one request, and D & E in another.
  2. Make a pull request. Have the left side ("Base") be commit A. For the right side ("head"), type in the commit number of C.
  3. Write the description for your first request.
  4. Make another request. For the base, type in the commit number of C, and for the head, put E (yours/master).
  5. Write the description.
  1. 确定要拉取的两个提交范围。这是我将使用的示例:(
    其他/主)A -> B -> C -> D -> E(你的/主)
    假设您想在一个请求中拉取 B 和 C,然后 D & E 在另一个。
  2. 发出拉取请求。将左侧(“Base”)设为提交 A。对于右侧(“head”),输入 C 的提交编号。
  3. 为您的第一个请求写下描述。
  4. 提出另一个请求。对于基础,输入 C 的提交编号,对于头部,输入 E(你的/主人)。
  5. 写下描述。

As I see it, the pull request sees commit C as a branch point. Or something.

在我看来,拉取请求将提交 C 视为一个分支点。或者其他的东西。

回答by BeanyTheSane

When you initially go to create the pull request, if you open two separate forms for a new pull request it will allow you to create them as long as they are pointed at different branches to be merged. For example, I could make two separate Requests, one to merge into master and another to merge into test.

当您最初创建拉取请求时,如果您为一个新拉取请求打开两个单独的表单,只要它们指向要合并的不同分支,您就可以创建它们。例如,我可以发出两个单独的请求,一个合并到 master,另一个合并到 test。

回答by markwusinich

I am new to Git and GitHub and had the same question as the OP.

我是 Git 和 GitHub 的新手,和 OP 有同样的问题。

I have found a solution, which probably was not available at the time of the OP.

我找到了一个解决方案,该解决方案在 OP 时可能不可用。

Situation: You have 3 changes, and you want each to be built off the previous, and each to have their own pull request (PR).

情况:您有 3 个更改,并且您希望每个更改都建立在前一个的基础上,并且每个更改都有自己的拉取请求 (PR)。

Problem: When you create the first PR that tries to pull develop into master, every thing looks fine, but then after you make the changes for the second PR, and merge them (using the same branch) all the changes are in the same PR.

问题:当您创建第一个 PR 试图将 develop 拉入 master 时,一切看起来都很好,但是在您对第二个 PR 进行更改并合并它们(使用相同的分支)之后,所有更改都在同一个 PR 中.

Mini Solution: Create a new branch

小方案:新建一个分支

git branch mini_change_2
git checkout mini_change_2

Now you push the code to GitHub and create the PR, but it defaults to Pull from mini_change_2 to master, except master does not yet have the changes from the first PR, so it includes all the changes from PR1 and PR2.

现在你将代码推送到 GitHub 并创建 PR,但它默认是从 mini_change_2 拉到 master,除了 master 还没有第一个 PR 的更改,所以它包括了 PR1 和 PR2 的所有更改。

Best Solution: Specify which branch you are merging to in PR2.

最佳解决方案:在 PR2 中指定您要合并到的分支。

Do not just accept the defaults when creating the second PR, say you are going pulling mini_chnage_2 to Develop, this will only show the changes in mini_change_2

在创建第二个 PR 时不要只接受默认值,比如你要拉 mini_chnage_2 到 Develop,这只会显示 mini_change_2 中的变化

Now create a new branch mini_change_3 and PR that to mini_change_3.

现在创建一个新的分支 mini_change_3 和 PR 到 mini_change_3。

The problem comes once you start merging them...but that is a different exercise.

一旦你开始合并它们,问题就来了……但这是一个不同的练习。