comparing-branches-visually
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseComparing Branches Visually
分支视觉对比
Create a visual before/after comparison of UI changes between two branches.
创建两个分支之间UI变更的前后视觉对比。
Workflow
工作流程
1. Set Up Two Worktrees
1. 设置两个工作树
Use subagents or git worktrees to run both branches simultaneously:
best-of-n-runnerbash
undefined使用子代理或git worktrees同时运行两个分支:
best-of-n-runnerbash
undefinedCreate a worktree for the base branch
为基准分支创建工作树
git worktree add /tmp/branch-compare-base main
git worktree add /tmp/branch-compare-base main
The current working directory has the feature branch
当前工作目录为功能分支
undefinedundefined2. Start Both Servers
2. 启动两个服务器
Start the base branch server on a different port:
bash
undefined在不同端口启动基准分支的服务器:
bash
undefinedIn the base worktree
在基准工作树中
cd /tmp/branch-compare-base && PORT=3001 npm run dev
cd /tmp/branch-compare-base && PORT=3001 npm run dev
Current branch is already on the default port (3000)
当前分支已在默认端口(3000)运行
undefinedundefined3. Identify Pages to Compare
3. 确定要对比的页面
Determine which pages are affected by the changes:
bash
git diff main --name-only | grep -E '\.(tsx?|jsx?|vue|svelte|css)'Map changed files to their routes (e.g. → ).
app/dashboard/page.tsx/dashboard找出受变更影响的页面:
bash
git diff main --name-only | grep -E '\.(tsx?|jsx?|vue|svelte|css)'将变更文件映射到对应的路由(例如 → )。
app/dashboard/page.tsx/dashboard4. Screenshot Both Versions
4. 对两个版本截图
For each affected page:
- to
browser_navigate(base branch)http://localhost:3001/<page> - → save as "before"
browser_take_screenshot - to
browser_navigate(feature branch)http://localhost:3000/<page> - → save as "after"
browser_take_screenshot
针对每个受影响的页面:
- 使用访问
browser_navigate(基准分支)http://localhost:3001/<page> - 执行→ 保存为“before”
browser_take_screenshot - 使用访问
browser_navigate(功能分支)http://localhost:3000/<page> - 执行→ 保存为“after”
browser_take_screenshot
5. Report
5. 生成报告
Present the comparison:
Visual Diff: feature/redesign-header vs main
/dashboard:
Before: [screenshot from main]
After: [screenshot from feature branch]
Changes: Header height reduced, nav links repositioned, new avatar dropdown
/settings:
Before: [screenshot]
After: [screenshot]
Changes: No visual differences detected展示对比结果:
视觉差异:feature/redesign-header vs main
/dashboard:
基准版本:[来自main分支的截图]
变更版本:[来自功能分支的截图]
变更内容:页眉高度降低,导航链接重新定位,新增头像下拉菜单
/settings:
基准版本:[截图]
变更版本:[截图]
变更内容:未检测到视觉差异6. Clean Up
6. 清理环境
bash
undefinedbash
undefinedStop the base branch server
停止基准分支的服务器
Remove the worktree
删除工作树
git worktree remove /tmp/branch-compare-base
undefinedgit worktree remove /tmp/branch-compare-base
undefinedTips
小贴士
- Test at a consistent viewport size (1280×800 is a good default)
- For mobile-first changes, also compare at 375px width
- If the app requires auth, log in on both ports first
- This pairs well with for PR descriptions
screenshotting-changelog
- 在一致的视口尺寸下进行测试(1280×800是不错的默认选择)
- 针对移动端优先的变更,同时在375px宽度下进行对比
- 如果应用需要授权,请先在两个端口完成登录
- 该流程与搭配使用,可优化PR描述
screenshotting-changelog