背景
在参与openharmony项目开发过程中,代码下载是repo进行管理的,当面临多个仓库修改需要提交代码的时候,由于仓库数量过多,参照官方给出的指导提交代码,会导致提交操作变得有些复杂。
为了解决该问题并做到如下几点:
- 一次源码下载
- 一次修改编译验证
- 一次提交代码
在曹同学的热心帮助下,推荐一个简单利用git设置多个远端仓库进行代码提交管理。
下载代码、fork仓库
下文均已OpenHarmony / kernel_liteos_a仓库为例。
- 下载主干代码(注意非fork仓库代码)
可直接参考官网给的下载方法 - fork需要提交的代码仓库
添加新的远端仓库
在kernel/liteos_a目录下,添加fork仓库为新的远端仓库:
git remote add --mirror=fetch mgy917 git@gitee.com:mgy917/kernel_liteos_a.git
查看新的远端仓库:
maguangyao@ubuntu:~/workspace/code/OpenHarmony/kernel/liteos_a$ git remote -v
mgy917 git@gitee.com:mgy917/kernel_liteos_a.git (fetch)
mgy917 git@gitee.com:mgy917/kernel_liteos_a.git (push)
origin https://openharmony.gitee.com/openharmony/kernel_liteos_a (fetch)
origin https://openharmony.gitee.com/openharmony/kernel_liteos_a (push)
修改代码、提交commit
git add foo.c
git commit
PUSH到远端仓库
关键的一步来了:
git push mgy917 HEAD:master
mgy917
为添加新的远端仓库创建的新remote仓库
HEAD
为本次提交的commit,也可以是本地分支名
master
是mgy917这个remote对应的分支,也可任意设置分支名
最后从fork仓库提交PR即可。
git 从远端仓库cherry-pick相关commit
# 添加远端仓库
git remote add fork https://gitee.com/fork_ohos/third_party_NuttX.git
# fetch远端
git fetch fork
# cherry-pick and done!
git cherry-pick a3993949bc5c49f9a0f88f8422d84f995b0473f3