Skip to content

Instantly share code, notes, and snippets.

@RitterHou
Forked from YimianDai/Submit-PR.md
Created July 14, 2022 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RitterHou/4a59560ccb33ebf764500f662ae764c8 to your computer and use it in GitHub Desktop.
Save RitterHou/4a59560ccb33ebf764500f662ae764c8 to your computer and use it in GitHub Desktop.
向开源项目提交 Pull Request

步骤

Part 1 - Local Repo Config

  1. 先 Fork 感兴趣项目,即 dmlc/gluon-cv
  2. Clone 到本地,git clone git@github.com:YimianDai/gluon-cv.git
  3. 添加源项目 dmlc/gluon-cv 作为 upstream 源,git remote add upstream https://github.com/dmlc/gluon-cv.git
  4. 禁止直接向 upstream 源 push,因为我们不是 dmlc 的人,没有 push 的权限,要提交代码必须通过 Pull Request,git remote set-url --push upstream no_push
  5. 创建并切换到本地的新分支 fixMixSoftmaxCrossEntropyLossgit checkout -b fixMixSoftmaxCrossEntropyLoss
    • 本地分支 master 的作用是与远程 upstream 的最新代码同步
    • 本地分支 fixMixSoftmaxCrossEntropyLoss 则是我们修改代码的战场

Part 2 - Fix Bug

  1. fix bug
  2. 在当前 fixMixSoftmaxCrossEntropyLoss 分支提交本地修改,git commit -m "XXXXXXX"
  3. Check upstream 源的最新状态
    • 在本地将 upstream 源的代码更新到最新,git fetch upstream
    • 将本地当前分支切换成 mastergit checkout master
    • upstream/master 的代码与本地当前默认分支,也就是本地 master 分支的代码融合:git merge upstream/master
  4. 将本地分支 fixMixSoftmaxCrossEntropyLoss 上的修改融合到最新的 master 分支上
    • 将本地当前分支切换成 fixMixSoftmaxCrossEntropyLossgit checkout -b fixMixSoftmaxCrossEntropyLoss
    • fixMixSoftmaxCrossEntropyLoss 的代码置于已经更新到最新的 master 分支的最新代码之后git rebase master,如下图所示:
  5. 向 Github 上自己的 fork 项目 YimianDai/gluon-cv 的分支 origin 提交自己的修改,因为 Pull Request 是将两个 Github 上的 repo 比较,所以一定要将本地的修改先推送到自己的 fork repo 上,git push origin fixMixSoftmaxCrossEntropyLoss:fixMixSoftmaxCrossEntropyLoss,参看 Ref. 4

Part 3 - Pull Request

  1. 提交 issue:描述发现的 Bug,这个可以作为对自己后面 Pull Request 的描述
  2. 是在自己 Fork 的项目界面,即 YimianDai/gluon-cv 的 Pull requests 的 Tab 中点击 New pull request,后面会自动跳到 dmlc/gluon-cv 的界面,如下所示:

Reference

  1. 查看当前是哪个分支?在工作目录下,
cat .git/HEAD
# ref: refs/heads/fixMixSoftmaxCrossEntropyLoss
  1. 关于 git rebase 非常好的一篇文章,Merging vs. Rebasing
  2. 向 github 的开源项目提交 PR 的步骤
  3. GIT: PUSHING TO A REMOTE BRANCH WITH A DIFFERENT NAME
  4. git push <REMOTENAME> <BRANCHNAME>
@RitterHou
Copy link
Author

  1. 将仓库fork到自己的名下
  2. clone自己名下的这个仓库到本地
  3. 在本地仓库中,新增一个针对原始仓库的上游配置
    git remote add upstream https://github.com/acgzone/vue-clicli.git
  4. 拉新的分支,在新的分支上面进行开发,开发结束
  5. 本地分支切换到master,从原始仓库的上游中,拉取原始仓库的最新代码到本地的master
  6. 把开发的内容从新的本地分支,合并到本地的master分支中
  7. push本地的master分支到自己名下的仓库上
  8. 从自己名下的仓库向原始仓库提交pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment