记Github上的一次PR

Github上PR提交 101

github上有教程说明如何提 PR (pull request)来参与开源项目,网上也有很多中文教程。这里简单地总结一下:

  1. 假设原项目为A,fork一个A_fork;
  2. 在本地 git clone A_fork;
  3. 进入 A_fork,添加 upstream:git remote add upstream https://github.com/xxx/A.git,并更新 git fetch upstream master;
  4. 基于 master 建立分支 patch;
  5. 切换到 patch 分支,做一些修改,并 commit,然后 push 到github;
  6. 在github中打开自己fork的项目,会看到提示类似: patch had recent pushes xx minutes ago,点击右边的按钮进入PR界面
  7. 在PR界面,确认下源库和要合并的分支–如果不正确,可以通过下拉列表选择正确的选项进行修正;
  8. 点击“Create a pull request”,接下来就等源库的管理员审核

管理员审核后,会给出相应的意见。我们需要根据反馈再做进一步的更改以完成最终的 PR 合并。

我遇到的提交PR后的反馈

简单提交了一个关于文档的 PR 后,收到如下回复:

change “base” branch of this PR: 4.x => 3.4 (use “Edit” button near PR title)
rebase your commits from 4.x onto 3.4 branch. For example:
git rebase -i –onto upstream/3.4 upstream/4.x
(check list of your commits, save and quit (Esc + “wq” + Enter)
where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
push rebased commits into source branch of your fork (with –force option)

根据提示,首先在 PR 的页面上将分支修改到 3.4。
接下来进入本地仓库。因为修改的分支是基于 4.x 分支的,我们需要先把修改合并到 4.x 上:

git rebase upstream/4.x

接着再执行 rebase onto 的操作:

git rebase -i --onto upstream/3.4 upstream/4.x

这句命令的意思是把对远端4.x所做的修改“移到”远端的 3.4分支。

最后将修改推上去:

git push --force

问题记录

clone 了 master分支,但是发现需要在 feature 分支建立分支修改提交再请求 PR。这时可以使用以下命令:

git checkout -t origin/feature

Comments