【Git进阶】基于文件(夹)拆分大PR - 几秋
source link: https://www.cnblogs.com/netry/p/git-split-large-pr.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
前段时间为了迁移一个旧服务到新项目,由此产生了一个巨大的PR,为了方便Code Review,最终基于文件夹,将其拆分成了多个较小的PR;现在这里记录下,后面可能还会需要。
为了方便演示,我创建了如下一个 large_pr_branch
到main
的大PR,99+的文件修改
通过观察,我们可以将这个大PR,基于项目的分层结构,拆成5个较小的PR,即 NewApi
-> Core
-> Infrastructure
-> UnitTest
-> IntegrationTest
。
第一步 获取差分文件
首先通过 git diff
命令得到每一层相较于main分支的差分文件(diff file),以 NewApi
为例
git diff main large_pr_branch -- NewApi > newApi.diff
newApi.diff
文件已经生成,
打开可以看到它包含了NewApi文件夹下所有的修改
第二步 创建接收分支
接下来我们基于main分支创建一个新分支,用来后面接收newApi.diff
git checkout maingit checkout -b newapi_folder_branch
第三步 应用差分文件
最后使用 git apply
命令将newApi.diff
应用到新分支
git apply newApi.diff
可以看到我们只将NewApi
文件夹下的45个文件修改引入到新分支 newapi_folder_branch
后面的事就简单了,提交修改之后,我们只需要基于 newapi_folder_branch
分支创建PR到main
分支,这样的得到PR,短小精悍,不会吓到同事^。
剩余文件夹重复上面的步骤即可。
如果你有更好的方式拆分大PR,欢迎评论区留言讨论^
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK