git 如何执行 GitHub 拉取请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14680711/
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
How to do a GitHub pull request
提问by tim peterson
How do I create and/or send a pull request to another repository hosted on GitHub?
如何创建和/或向托管在 GitHub 上的另一个存储库发送拉取请求?
采纳答案by tim peterson
To learn how to make a pull request I just followed two separate help pages on Github (linked below as bullet points). The following command line commands are for Part 1. Part 2, the actual pull request, is done entirely on Github's website.
为了学习如何发出拉取请求,我只关注了 Github 上的两个单独的帮助页面(以下链接为要点)。以下命令行命令适用于第 1 部分。第 2 部分,实际的拉取请求,完全在 Github 的网站上完成。
$ git clone https://github.com/tim-peterson/dwolla-php.git
$ cd dwolla-php
$ git remote add upstream https://github.com/Dwolla/dwolla-php.git
$ git fetch upstream
// make your changes to this newly cloned, local repo
$ git add .
$ git commit -m '1st commit to dwolla'
$ git push origin master
Part 1: fork someone's repo: https://help.github.com/articles/fork-a-repo
- click the 'fork' button on the repo you want to contribute to, in this case: Dwolla's PHP repo(Dwolla/dwolla-php)
- get the URL for your newly created fork, in this case: https://github.com/tim-peterson/dwolla-php.git(tim-peterson/dwolla-php)
- type the
git clone->cd dwolla-php->git remote->git fetch
sequence above to clone your fork somewhere in your computer (i.e., "copy/paste" it to, in this case:third_party TimPeterson$
) and sync it with the master repo (Dwolla/dwolla-php) - make your changes to your local repo
- type the
git add->git commit->git push
sequence above to push your changes to the remote repo, i.e., your fork on Github (tim-peterson/dwolla-php)
Part 2: make pull-request: https://help.github.com/articles/using-pull-requests
- go to your fork'swebpage on Github (https://github.com/tim-peterson/dwolla-php)
- click 'pull-request' button
- give pull-request a name, fill in details of what changes you made, click submit button.
- you're done!!
第 1 部分:fork 某人的 repo:https: //help.github.com/articles/fork-a-repo
- 单击您想要贡献的存储库上的“fork”按钮,在本例中:Dwolla 的 PHP 存储库(Dwolla/dwolla-php)
- 获取新创建的 fork 的 URL,在这种情况下:https: //github.com/tim-peterson/dwolla-php.git(tim-peterson/dwolla-php)
- 键入
git clone->cd dwolla-php->git remote->git fetch
上面的序列以将您的 fork 克隆到您计算机中的某个位置(即“复制/粘贴”它,在这种情况下third_party TimPeterson$
:)并将其与主存储库(Dwolla/dwolla-php)同步 - 对本地存储库进行更改
- 键入
git add->git commit->git push
上面的序列以将您的更改推送到远程仓库,即您在 Github 上的分支 (tim-peterson/dwolla-php)
第 2 部分:发出拉取请求:https: //help.github.com/articles/using-pull-requests
- 转到您在 Github 上的 fork网页 ( https://github.com/tim-peterson/dwolla-php)
- 单击“拉取请求”按钮
- 给 pull-request 起一个名字,填写你所做的更改的详细信息,点击提交按钮。
- 你完成了!!
回答by VonC
(In addition of the official "GitHub Help 'Using pull requests' page",
see also "Forking vs. Branching in GitHub", "What is the difference between origin and upstream in GitHub")
(除了官方的“ GitHub Help 'Using pull requests' page”,
另见“ GitHub中的分叉与分支”,“ GitHub中的origin和upstream有什么区别”)
Couple tips on pull-requests:
关于拉取请求的一些提示:
Assuming that you have first forked a repo, here is what you should do in that fork that you own:
假设您首先对 repo 进行了分叉,那么您应该在您拥有的分叉中执行以下操作:
- create a branch: isolate your modifications in a branch. Don't create a pull request from
master
, where you could be tempted to accumulate and mix severalmodifications at once. - rebase that branch: even if you already did a pull request from that branch, rebasing it on top of
origin/master
(making sure your patch is still working) will update the pull request automagically (no need to click on anything) - update that branch: if your pull request is rejected, you simply can add new commits, and/or redo your history completely: it will activate your existing pull request again.
- "focus" that branch: i.e., make its topic "tight", don't modify thousands of class and the all app, only add or fix a well-defined feature, keeping the changes small.
- delete that branch: once accepted, you can safely delete that branch on your fork (and
git remote prune origin
). The GitHub GUI will propose for you to delete your branch in your pull-request page.
- 创建分支:在分支中隔离您的修改。不要从 中创建拉取请求
master
,在那里您可能会试图一次积累和混合多个修改。 - rebase 该分支:即使您已经从该分支执行了拉取请求,将其重新设置在其上
origin/master
(确保您的补丁仍在工作)将自动更新拉取请求(无需单击任何内容) - 更新该分支:如果您的拉取请求被拒绝,您只需添加新的提交,和/或完全重做您的历史记录:它将再次激活您现有的拉取请求。
- “聚焦”那个分支:即,使其主题“紧凑”,不要修改数千个类和所有应用程序,只添加或修复定义明确的功能,保持更改很小。
- 删除该分支:一旦被接受,您就可以安全地删除您的 fork(和
git remote prune origin
)上的该分支。GitHub GUI 将建议您删除拉取请求页面中的分支。
Note: to writethe Pull-Request itself, see "How to write the perfect pull request" (January 2015, GitHub)
注意:要编写Pull-Request 本身,请参阅“如何编写完美的 pull request”(2015 年 1 月,GitHub)
March 2016: New PR merge button option: see "Github squash commits from web interface on pull request after review comments?".
2016 年 3 月:新的 PR 合并按钮选项:请参阅“ Github squash 在评论后从 Web 界面提交拉取请求?”。
The maintainer of the repo can chose to merge --squash
those PR commits.
回购的维护者可以选择merge --squash
那些 PR 提交。
After a Pull Request
拉取请求之后
Regarding the last point, since April, 10th 2013, "Redesigned merge button", the branch is deleted for you:
关于最后一点,自 2013 年 4 月 10 日起,“重新设计合并按钮”,为您删除了分支:
Deleting branches after you merge has also been simplified.
Instead of confirming the delete with an extra step, we immediately remove the branch when you delete it and provide a convenient link to restore the branch in the event you need it again.
合并后删除分支也得到了简化。
我们不会通过额外的步骤确认删除,而是在您删除分支时立即删除它,并提供方便的链接以在您再次需要时恢复该分支。
That confirms the best practice of deleting the branch after merging a pull request.
这证实了合并拉取请求后删除分支的最佳实践。
pull-request vs. request-pull
拉请求与请求拉
pull request isn't an official "git" term.
Git uses therequest-pull
(!) commandto build a request for merging:
It "summarizes the changes between two commits to the standard output, and includes the given URL in the generated summary."
Github launches its own version since day one (February 2008), but redesigned that feature in May 2010, stating that:Pull Request = Compare View + Issues + Commit comments
拉取请求不是官方的“git”术语。
Git 使用request-pull
(!) 命令来构建合并请求:
它“将两次提交之间的更改汇总到标准输出,并在生成的汇总中包含给定的 URL。”
Github从第一天(2008 年 2 月)开始推出自己的版本,但在 2010 年 5 月重新设计了该功能,并指出:Pull Request = Compare View + Issues + Commit comments
e-notes for "reposotory" (sic)
“存储库”的电子笔记(原文如此)
<humour>
<humour>
That (pull request) isn't even defined properly by GitHub!
GitHub 甚至没有正确定义那个(拉取请求)!
Fortunately, a true business news organization would know, and there is an e-note in order to replace pull-replace by 'e-note':
幸运的是,真正的商业新闻机构会知道,并且有一个e-note 可以用 'e-note' 替换 pull-replace:
So if your reposotory needs a e-note... ask Fox Business. They are in the know.
所以,如果你的回购Ø保守党需要一个电子笔记...问问福克斯商业。他们是知情的。
</humour>
</humour>
回答by Farhan
In order to make a pull request you need to do the following steps:
为了发出拉取请求,您需要执行以下步骤:
- Fork a repository (to which you want to make a pull request). Just click the fork button the the repository page and you will have a separate github repository preceded with your github username.
- Clone the repository to your local machine. The Github software that you installed on your local machine can do this for you. Click the clone button beside the repository name.
- Make local changes/commits to the files
- sync the changes
- go to your github forked repository and click the "Compare & Review" green button besides the branch button. (The button has icon - no text)
- A new page will open showing your changes and then click the pull request link, that will send the request to the original owner of the repository you forked.
- Fork 一个存储库(您要向其发出拉取请求)。只需单击存储库页面上的 fork 按钮,您将拥有一个单独的 github 存储库,前面带有您的 github 用户名。
- 将存储库克隆到本地计算机。您安装在本地计算机上的 Github 软件可以为您执行此操作。单击存储库名称旁边的克隆按钮。
- 对文件进行本地更改/提交
- 同步更改
- 转到您的 github 分叉存储库,然后单击分支按钮旁边的“比较和”绿色按钮。(按钮有图标 - 没有文字)
- 将打开一个新页面,显示您的更改,然后单击拉取请求链接,该链接会将请求发送给您分叉的存储库的原始所有者。
It took me a while to figure this, hope this will help someone.
我花了一段时间才弄清楚这一点,希望这会对某人有所帮助。
回答by sudo bangbang
I've started a project to help people making their first GitHub pull request. You can do the hands-on tutorial to make your first PR here
我已经启动了一个项目来帮助人们提出他们的第一个 GitHub 拉取请求。您可以在此处进行动手教程来制作您的第一个 PR
The workflow is simple as
工作流程很简单
- Fork the repo in github
- Get clone url by clicking on clone repo button
- Go to terminal and run
git clone <clone url you copied earlier>
- Make a branch for changes you're makeing
git checkout -b branch-name
- Make necessary changes
- Commit your changes
git commit
- Push your changes to your fork on GitHub
git push origin branch-name
- Go to your fork on GitHub to see a
Compare and pull request
button - Click on it and give necessary details
- 在 github 中分叉 repo
- 通过单击克隆回购按钮获取克隆网址
- 转到终端并运行
git clone <clone url you copied earlier>
- 为您所做的更改创建一个分支
git checkout -b branch-name
- 进行必要的更改
- 提交您的更改
git commit
- 将您的更改推送到 GitHub 上的 fork
git push origin branch-name
- 转到您在 GitHub 上的分支以查看
Compare and pull request
按钮 - 单击它并提供必要的详细信息
回答by Sphinxxx
For those of us who have a github.com account, but only get a nasty error message when we type "git" into the command-line, here's how to do it all in your browser :)
对于我们这些拥有 github.com 帐户的人来说,当我们在命令行中键入“git”时只会收到令人讨厌的错误消息,以下是在浏览器中执行所有操作的方法:)
- Same as Tim and Farhan wrote: Fork your own copy of the project:
- After a few seconds, you'll be redirected to your own forked copy of the project:
- Navigate to the file(s) you need to change and click "Edit this file" in the toolbar:
- After editing, write a few words describing the changes and then "Commit changes", just as well to the master branch (since this is only your own copy and not the "main" project).
- Repeat steps 3 and 4 for all files you need to edit, and then go back to the root of your copyof the project. There, click the green "Compare, review..." button:
- Finally, click "Create pull request" ..and then "Create pull request" againafter you've double-checked your request's heading and description:
回答by tamalet
I followed tim peterson's instructions but I created a local branch for my changes. However, after pushing I was not seeing the new branch in GitHub. The solution was to add -u to the push command:
我遵循了 tim peterson 的指示,但我为我的更改创建了一个本地分支。但是,在推送之后我没有在 GitHub 中看到新的分支。解决方案是将 -u 添加到 push 命令:
git push -u origin <branch>
回答by stason
I wrote a bash program that does all the work of setting up a PR branch for you. It performs forking if needed, syncing with the upstream, setting up upstream remote, etc. and you just need to commit your modifications, push and submit a PR.
我编写了一个 bash 程序,它为您完成了设置 PR 分支的所有工作。如果需要,它会执行分叉、与上游同步、设置上游远程等,您只需要提交修改、推送和提交 PR。
Here is how you run it:
这是你如何运行它:
github-make-pr-branch ssh your-github-username orig_repo_user orig_repo_name new-feature
You will find the program hereand its repository also includes a step-by-step guide to performing the same process manually if you'd like to understand how it works, and also extra information on how to keep your feature branch up-to-date with the upstream master and other useful tidbits.
如果您想了解它是如何工作的,您将在此处找到该程序,其存储库还包括手动执行相同过程的分步指南,以及有关如何使您的功能分支保持最新状态的额外信息-与上游大师和其他有用的花絮约会。
回答by flywire
The Simplest GitHub Pull Requestis from the web interfacewithout using git.
在最简单的GitHub拉请求是从Web界面,而不使用Git。
- Register a GitHub account, login then go to the page in the repository you want to change.
Click the pencilicon,
search for text near the location, make any edits you want then preview them to confirm. Give the proposed change a description up to 50 characters and optionally an extended description then click the Propose file Changebutton.
If you're reading this you won't have write access to the repository (project folders) so GitHub will create a copy of the repository (actually a branch) in your account. Click the Create pull requestbutton.
- Give the Pull Request a description and add any comments then click Create pull requestbutton.
- 注册一个 GitHub 帐户,登录然后转到要更改的存储库中的页面。
点击铅笔图标,
搜索该位置附近的文本,进行您想要的任何编辑,然后预览它们以进行确认。为提议的更改提供最多 50 个字符的描述和可选的扩展描述,然后单击提议文件更改按钮。
如果您正在阅读本文,您将没有对存储库(项目文件夹)的写访问权限,因此 GitHub 将在您的帐户中创建存储库的副本(实际上是一个分支)。单击创建拉取请求按钮。
- 为拉取请求提供描述并添加任何评论,然后单击创建拉取请求按钮。