如何进行cherry

42次阅读
没有评论

共计 4040 个字符,预计需要花费 11 分钟才能阅读完成。

如何进行 cherry-pick 的分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

尽管 Kubernetes 拥有众多分支,但社区主要围绕在 master 分支进行开发。即便其他分支存在 bug,通常也是先在 master 分支进行修复,然后再 cherry-pick 到其他分支。

软件开发不可避免的会出现 bug,所以经常需要从 master 同步一些补丁到其他仍在维护的分支。而同步的手段可以有多种:

手动提交 PR 到其他分支;

自动提交 PR 到其他分支;

一般来说,自动提交的方式更普遍,它能把某个 master 已合入的 PR 自动 cherry-pick 到你指定的分支上,而手动提交只有在极少数情况下才会使用。

自动 cherry-pick

使用 Kubernetes 仓库中 hack/cherry_pick_pull.sh 脚本可以把一个合入到 master 分支的 PR 同步到其他分支。它可以帮你自动完成提交 PR 的所有过程。

前提条件

使用 hack/cherry_pick_pull.sh 自动同步需要满足一定的前提条件:

你必须已经签署了 CLA 声明,这也是每个贡献者必须要签署的内容;

针对 master 的 PR 已经被合入;

你的 Github 帐号中已经 fork 了 Kubernetes 仓库,并且你本地的 shell 中已经 clone 了此 fork 仓库;

你本的仓库中必须添加的远端仓库名为 upstream(通过命令 git remote add upstream https://github.com/kubernetes/kubernetes.git);

在你环境变量中添加了 export GITHUB_USER= GitHub ID;

已安装了 hub 命令行工具;

如果你已经参与过代码贡献,那么这些要求一般都会自动满足,除了最后两个。

hub 命令行工具为 GitHub 官方提供的工具,用于从命令行操作 GitHub。而环境变量中需要添加 GITHUB_USER 正是因为 hub 命令行工具会使用。如果你还没有安装,可以使用命令 go get github.com/github/hub 安装它。

如何自动 cherry-pick

比如,需要将 master 上的 PR #85444 同步到分支 release-1.17,在前面条件都具备的情况下,只需要使用如下命令:

hack/cherry_pick_pull.sh upstream/release-1.17 85444

注意:此脚本会自动创建 PR,不要轻易尝试,除非你真的需要这么做。

脚本执行过程中会有大量信息输出,可以了解到具体执行过程:

[root@ecs-d8b6 kubernetes]# hack/cherry_pick_pull.sh upstream/release-1.17 85444
+++ Updating remotes...
Fetching upstream
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Total 48 (delta 34), reused 34 (delta 34), pack-reused 14
Unpacking objects: 100% (48/48), done.
From https://github.com/kubernetes/kubernetes
 d87c921a516..1f913b45820 master -  upstream/master
 c0f31a4ef63..5c651b7bd5f release-1.16 -  upstream/release-1.16
 486425533b6..27babd49b95 release-1.17 -  upstream/release-1.17
 * [new tag] v1.17.0-rc.1 -  v1.17.0-rc.1
Fetching origin
+++ Creating local branch automated-cherry-pick-of-#85444-upstream-release-1.17-1574748271
Branch  automated-cherry-pick-of-#85444-upstream-release-1.17-1574748271  set up to track remote branch  release-1.17  from  upstream .
Switched to a new branch  automated-cherry-pick-of-#85444-upstream-release-1.17-1574748271 
+++ Downloading patch to /tmp/85444.patch (in case you need to do this again)
+++ About to attempt cherry pick of PR. To reattempt:
 $ git am -3 /tmp/85444.patch
Applying: Provided a mechanism to re-register hidden metrics.
+++ I m about to do the following to push to GitHub (and I m assuming origin is your personal fork):
 git push origin automated-cherry-pick-of-#85444-upstream-release-1.17-1574748271:automated-cherry-pick-of-#85444-upstream-release-1.17
+++ Proceed (anything but  y  aborts the cherry-pick)? [y/n] y
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 2.19 KiB | 1.09 MiB/s, done.
Total 10 (delta 8), reused 0 (delta 0)
remote: Resolving deltas: 100% (8/8), completed with 8 local objects.
remote: 
remote: Create a pull request for  automated-cherry-pick-of-#85444-upstream-release-1.17  on GitHub by visiting:
remote: https://github.com/RainbowMango/kubernetes/pull/new/automated-cherry-pick-of-%2385444-upstream-release-1.17
remote: 
To https://github.com/RainbowMango/kubernetes.git
 * [new branch] automated-cherry-pick-of-#85444-upstream-release-1.17-1574748271 -  automated-cherry-pick-of-#85444-upstream-release-1.17
+++ Creating a pull request on GitHub at RainbowMango:automated-cherry-pick-of-#85444-upstream-release-1.17
https://github.com/kubernetes/kubernetes/pull/85627
+++ Returning you to the master branch and cleaning up.

实际上该脚本实际上模拟了手工操作:

创建一个本地分支,比如 automated-cherry-pick-of-#85444-upstream-release-1.17;

通过 hub 工具获取 PR 的 commit 信息(可能有多个 commit);

将 upstream/master 中相关的 commit cherry-pick 到本地分支中;

将本地分支推送到远端(origin);

使用 GitHub 的接口提交 PR;

手动 cherry-pick

手动 cherry-pick 一般不常发生,因为大多数情况下自动 cherry-pick 都可以胜任。只有在冲突比较大时,需要手工处理冲突时才会手动 cherry-pick。

手动 chery-pick,需要处理冲突,处理完成后提交 PR 的过程与向 master 提交完全一致,这里不再赘述。

提交到 release 分支的 PR 审核过程与提交到 master 分支的略有不同,提交到 release 分支的 PR 除了需要相关领域的 approver 批准以外,还需要 release manager 批准才可以合入。

提交到 release 分支的 PR,自动会被添加上 do-not-merge/cherry-pick-not-approved 标签,只有 release manager 批准后才会去除该标签,然后 CI 才会合入该 PR。

看完上述内容,你们掌握如何进行 cherry-pick 的分析的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注丸趣 TV 行业资讯频道,感谢各位的阅读!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-16发表,共计4040字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)