Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何向开源项目提交 PR #6

Open
zhangsibo1129 opened this issue Aug 3, 2023 · 0 comments
Open

如何向开源项目提交 PR #6

zhangsibo1129 opened this issue Aug 3, 2023 · 0 comments
Labels
Ascend Something isn't working publish New feature or request

Comments

@zhangsibo1129
Copy link

zhangsibo1129 commented Aug 3, 2023

作者:@zhangsibo1129

以 ONNX Runtime 开源项目为例,介绍如何向开源项目提交 PR

开发分支管理

1. 开发仓库关系

在贡献开源的场景下,开发涉及到三个仓库:Github-Upstream 上游仓库,Github-Origin 个人远程仓库,Local Repository 本地仓库。如下图所示,以 ONNX Runtime 开源项目为例,上游仓库对应 microsoft/onnxruntime,个人远程仓库对应 zhangsibo1129/onnxruntime,本地仓库对应着克隆到本地计算机的代码

repos

三者关系如图,首先从 Github-Upstream 上游仓库 Fork 一个个人远程仓库 Github-Origin,并从上游仓库 clone/fetch 最新提交信息同步到本地仓库;在本地仓库创建开发分支,进行代码开发,开发完毕后将代码 push 到个人远程仓库的分支;最后从个人远程仓库向上游仓库主干分支提交 Pull Request。

2. 个人仓库创建

进入 ONNX Runtime 开源项目主页,Fork 该项目到个人仓库

fork

克隆代码到本地仓库,设置上游仓库和个人远程仓库

# 从 upstream 克隆项目到本地
git clone https://github.com/microsoft/onnxruntime.git

# 删除当前远程仓库
git remote rm origin

# 添加 upstream 远程仓库
git remote add upstream [email protected]:microsoft/onnxruntime.git

# 添加 origin 远程仓库
git remote add origin [email protected]:zhangsibo1129/onnxruntime.git

# 查看远程仓库
git remote -v

显示如下,配置完毕

origin  [email protected]:zhangsibo1129/onnxruntime.git (fetch)
origin  [email protected]:zhangsibo1129/onnxruntime.git (push)
upstream        [email protected]:microsoft/onnxruntime.git (fetch)
upstream        [email protected]:microsoft/onnxruntime.git (push)

3. 开发分支创建

新建并切换到本地开发分支

git checkout -b my_dev_branch

本地代码开发

1. 从上游获取更新

同步 upstream 与 origin 仓库的 main 分支

# 获取 upstream 仓库的更新
git fetch upstream 

# 切换到本地 main 分支
git checkout main

# 将 upstream/main 分支合入本地 main 分支
git merge upstream/main

# 将本地 main 分支推送到 origin 仓库 main 分支
git push origin main

2. 变基到最新分支

将当前开发分支进行变基操作

# 切换到本地开发分支
git checkout my_dev_branch

# 变基到最新的 upstream main 分支
git rebase upstream/main

3. 代码开发

修改onnxruntime/core/providers/cann/cann_execution_provider.cc代码,运行git diff

提交代码并创建 PR

代码开发完毕,但只存在本地仓库中,要先推送到个人远程仓库,才能向上游仓库提交 PR

1. 推送到个人远程仓库

提交代码到本地开发分支

# 添加修改文件
git add onnxruntime/core/providers/cann/cann_execution_provider.cc

# 向本地仓库提交更改
git commit -m "Fix registration of Identity operator"

将本地开发分支推送到远程个人仓库

git push origin my_dev_branch

此时,修改后的代码已经合入了远程个人仓库的开发分支 origin/my_dev_branch

2. 向上游创建 PR

创建 PR 的作用是将 origin/my_dev_branch 合入 upstream/main,从而实现将自己开发的代码贡献给上游社区,该操作在 Github 网页上完成,如下图所示在个人远程仓库页面创建新 PR

pr0

选择正确的分支,依次按提示点击

pr1

review 以及静态检查、CI 构建等通过后,committer 会进行合入操作,合入成功显示如下信息

merged

@zhangsibo1129 zhangsibo1129 added Ascend Something isn't working publish New feature or request labels Aug 3, 2023
@Yikun Yikun added publish New feature or request and removed publish New feature or request labels Aug 3, 2023
@Yikun Yikun added the publish New feature or request label Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ascend Something isn't working publish New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants