如何获取Patch Set间的真实差异而非差异的差异(关联Rebase)
Gerrit查看Patch Set间真实差异的方法
问题场景
基础文件test.txt:
This is first line This is second line This is third line This is forth line
上传Patch A(Patch Set 1):
This is first line This is second line This is third line This is forth line // patch A change
合并Patch B后,文件变为:
This is first line // patch B change This is second line This is third line This is forth line
将Patch A重基于最新代码后生成Patch Set 2:
This is first line // patch B change This is second line This is third line This is forth line // patch A change
此时在Gerrit中查看Patch Set 1和2的差异,显示无差异,但实际两个Patch Set的代码存在来自Patch B的变更差异。
解决方法
Gerrit界面指定对比基线
在变更页面的「对比」选项中,不要使用默认的相邻Patch Set对比,手动选择Patch Set 1和2对应的提交哈希,或选择对比Patch Set与各自的父提交。也可直接构造对比URL:https://你的Gerrit地址/changes/[变更ID]/revisions/[Patch Set 2编号]/diff?base=[Patch Set 1编号](替换实际参数)。本地Git命令对比
先拉取Gerrit上的变更到本地:git fetch gerrit refs/changes/[XX]/[变更ID]/[Patch Set 1编号] && git fetch gerrit refs/changes/[XX]/[变更ID]/[Patch Set 2编号]再直接对比两个提交:
# 对比Patch Set 2和它的父提交 git diff FETCH_HEAD~1 FETCH_HEAD # 或直接对比两个Patch Set的提交哈希 git diff [Patch Set 1提交哈希] [Patch Set 2提交哈希]调整Gerrit差异显示策略
在Gerrit设置的「差异显示」板块,关闭「忽略合并引入的变更」选项,或切换差异算法为「精确对比」(不同版本选项名称可能略有差异),强制Gerrit显示两个Patch Set间的所有内容差异。
内容的提问来源于stack exchange,提问作者DaDaNow
相关产品推荐
相关产品推荐

