GitHub Fork后,如何对比自有分支与上游仓库分支?含Web及CLI方案
对比Fork分支与上游分支变更的方法
GitHub Web界面操作步骤
- 打开你的Fork仓库页面,切换到目标分支
property-source - 点击页面上方的Compare按钮(位于"Code"按钮旁)
- 在对比页面调整两端分支:
- 左侧选择上游仓库
springframeworkguru/sfg-di的property-source分支 - 右侧选择你自己仓库
steranka/udemy-sfg-di的property-source分支
- 左侧选择上游仓库
- 页面会直接展示两个分支的所有差异,无需创建Pull Request
提示:如果Web端没有自动显示上游仓库选项,可直接访问手动构造的对比URL:
https://github.com/springframeworkguru/sfg-di/compare/property-source...steranka/udemy-sfg-di:property-source
gh-cli(GitHub命令行)实现方式
确保已安装并登录gh-cli,执行以下命令:
# 终端直接展示差异 gh repo compare springframeworkguru/sfg-di:property-source...steranka/udemy-sfg-di:property-source # 或直接在浏览器打开对比页面 gh repo compare springframeworkguru/sfg-di:property-source...steranka/udemy-sfg-di:property-source --web
Git CLI本地对比(可选)
若偏好本地终端操作,可执行:
# 拉取上游仓库最新代码 git fetch upstream # 对比本地分支与上游对应分支的差异 git diff upstream/property-source property-source
内容的提问来源于stack exchange,提问作者PatS
相关产品推荐
相关产品推荐

