git%3Acompare-worktrees by neolabhq/context-engineering-kit
npx skills add https://github.com/neolabhq/context-engineering-kit --skill git:compare-worktrees你的任务是比较 git 工作树之间的文件和目录,帮助用户理解跨分支或工作树的代码差异。
关键:请严格按照以下步骤执行:
检查当前状态:运行 git worktree list 以显示所有现有工作树及其位置
解析用户输入:对每个提供的参数进行分类:
* **无参数**:交互模式 - 询问用户要比较什么
* **`--stat`**:显示差异的摘要统计信息(更改的文件、插入行、删除行)
* **工作树路径**:与 `git worktree list` 输出中某个工作树根目录匹配的路径
* **分支名称**:与某个工作树中的分支名称匹配的名称
* **文件/目录路径**:当前工作树内要比较的路径
3. 确定比较目标(要比较的工作树):a. 如果用户提供了工作树路径:使用这些路径作为比较目标 b. 如果用户指定了分支名称:从 git worktree list 中查找这些分支对应的工作树 c. 如果除了当前工作树外只有一个工作树:使用当前工作树和那个工作树作为比较目标 d. 如果存在多个工作树且未指定任何目标:呈现列表并询问用户要比较哪些 e. 如果不存在其他工作树:提供使用 git diff 与分支进行比较的选项
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
* "比较整个工作树?" 或
* "比较特定文件/目录?(输入路径)"
5. 执行比较:
对于工作树之间的特定文件:
diff <worktree1>/<path> <worktree2>/<path>
# 或者使用统一差异格式:
diff -u <worktree1>/<path> <worktree2>/<path>
对于工作树之间的目录:
diff -r <worktree1>/<directory> <worktree2>/<directory>
# 或者仅显示摘要:
diff -rq <worktree1>/<directory> <worktree2>/<directory>
对于分支级别的比较(使用 git diff):
git diff <branch1>..<branch2> -- <path>
# 或者显示统计摘要:
git diff --stat <branch1>..<branch2>
对于与当前工作目录的比较:
diff <current-file> <other-worktree>/<file>
6. 格式化并呈现结果:
* 显示清晰的标题,说明正在比较的内容
* 对于大型差异,提供先显示摘要的选项
* 突出显示重要更改(新文件、已删除文件、重命名文件)
* 提供每个工作树所包含分支的上下文信息
| 模式 | 描述 | 命令模式 |
|---|---|---|
| 文件差异 | 比较工作树之间的单个文件 | diff -u <wt1>/file <wt2>/file |
| 目录差异 | 递归比较目录 | diff -r <wt1>/dir <wt2>/dir |
| 仅摘要 | 显示哪些文件不同(不显示内容) | diff -rq <wt1>/ <wt2>/ |
| Git 差异 | 使用 git 的 diff(基于分支) | git diff branch1..branch2 -- path |
| 统计视图 | 显示更改统计信息 | git diff --stat branch1..branch2 |
该命令使用 git worktree list 查找工作树:
/home/user/project abc1234 [main]
/home/user/project-feature def5678 [feature-x]
/home/user/project-hotfix ghi9012 [hotfix-123]
根据此输出,命令提取:
比较工作树之间的特定文件:
> /git:compare-worktrees src/app.js
# 提示选择与哪个工作树进行比较
# 显示当前工作树与所选工作树之间 src/app.js 的差异
比较两个特定工作树之间:
> /git:compare-worktrees ../project-main ../project-feature src/module.js
# 比较两个指定工作树之间的 src/module.js
比较多个文件/目录:
> /git:compare-worktrees src/app.js src/utils/ package.json
# 显示工作树之间所有三个路径的差异
比较整个目录:
> /git:compare-worktrees src/
# 显示工作树之间 src/ 目录中的所有差异
获取摘要统计信息:
> /git:compare-worktrees --stat
# 显示哪些文件不同以及行数统计
交互模式:
> /git:compare-worktrees
# 列出可用的工作树
# 询问要比较哪些
# 询问特定路径或整个工作树
按分支名称与分支工作树比较:
> /git:compare-worktrees feature-x
# 查找 feature-x 分支的工作树并进行比较
比较分支工作树之间的特定路径:
> /git:compare-worktrees main feature-x src/ tests/
# 比较 main 和 feature-x 工作树之间的 src/ 和 tests/ 目录
文件比较标题:
Comparing: src/app.js
From: /home/user/project (main)
To: /home/user/project-feature (feature-x)
---
[diff output]
摘要输出:
Worktree Comparison Summary
===========================
From: /home/user/project (main)
To: /home/user/project-feature (feature-x)
Files only in main:
- src/deprecated.js
Files only in feature-x:
+ src/new-feature.js
+ src/new-feature.test.js
Files that differ:
~ src/app.js
~ src/utils/helpers.js
~ package.json
Statistics:
3 files changed
2 files added
1 file removed
# 查看功能分支中的更改
> /git:compare-worktrees --stat
> /git:compare-worktrees src/components/
# 比较两个功能如何实现相似的功能
> /git:compare-worktrees ../project-feature-1 ../project-feature-2 src/auth/
# 检查特定文件是否不同
> /git:compare-worktrees package.json
# 在合并前审查所有更改(一起比较 src 和 tests)
> /git:compare-worktrees --stat
> /git:compare-worktrees src/ tests/
# src/ 和 tests/ 目录都将被比较
git worktree list 输出进行比较来自动检测参数类型:* 匹配工作树根目录的路径 → 视为要比较的工作树
* 匹配工作树中分支的名称 → 视为要比较的工作树
* 其他路径 → 视为要在工作树内比较的文件/目录
多个路径:当提供多个文件/目录路径时,所有路径都会在选定的工作树之间进行比较(不仅仅是第一个)。
工作树路径:指定工作树时,请使用完整路径或相对于当前目录的路径(例如,../project-feature)
分支与工作树:如果指定分支名称,该命令会查找检出该分支的工作树。如果该分支不存在工作树,则会建议改用 git diff。
大型差异:对于大型目录,该命令将提供先显示摘要再显示完整差异输出的选项。
二进制文件:二进制文件会被检测并报告为"二进制文件不同",而不显示实际的差异。
文件权限:如果文件权限不同,差异也会显示文件权限的更改。
无工作树:如果不存在其他工作树,该命令将解释如何创建一个,并提供使用 git diff 进行分支比较的选项。
首先使用 /git:create-worktree 设置用于比较的工作树:
# 为比较创建工作树
> /git:create-worktree feature-x, main
# 已创建:../project-feature-x 和 ../project-main
# 现在进行比较
> /git:compare-worktrees src/
"未找到其他工作树"
/git:create-worktree <branch> 创建工作树git diff 进行无需工作树的分支比较"未找到分支的工作树"
git worktree list 查看可用的工作树/git:create-worktree <branch> 创建工作树"工作树中不存在路径"
每周安装数
214
代码仓库
GitHub 星标数
699
首次出现
2026年2月19日
安装于
opencode208
github-copilot207
codex207
gemini-cli206
kimi-cli204
cursor204
Your job is to compare files and directories between git worktrees, helping users understand differences in code across branches or worktrees.
CRITICAL: Perform the following steps exactly as described:
Current state check : Run git worktree list to show all existing worktrees and their locations
Parse user input : Classify each provided argument:
--stat : Show summary statistics of differences (files changed, insertions, deletions)git worktree listDetermine comparison targets (worktrees to compare): a. If user provided worktree paths: Use those as comparison targets b. If user specified branch names: Find the worktrees for those branches from git worktree list c. If only one worktree exists besides current: Use current and that one as comparison targets d. If multiple worktrees exist and none specified: Present list and ask user which to compare e. If no other worktrees exist: Offer to compare with a branch using git diff
Determine what to compare (files/directories within worktrees): a. If user specified file(s) or directory(ies) paths: Compare ALL of them b. If no specific paths given: Ask user:
Execute comparison :
For specific files between worktrees:
diff <worktree1>/<path> <worktree2>/<path>
# Or for unified diff format:
diff -u <worktree1>/<path> <worktree2>/<path>
For directories between worktrees:
diff -r <worktree1>/<directory> <worktree2>/<directory>
# Or for summary only:
diff -rq <worktree1>/<directory> <worktree2>/<directory>
For branch-level comparison (using git diff):
git diff <branch1>..<branch2> -- <path>
# Or for stat summary:
git diff --stat <branch1>..<branch2>
For comparing with current working directory:
diff <current-file> <other-worktree>/<file>
6. Format and present results :
* Show clear header indicating what's being compared
* For large diffs, offer to show summary first
* Highlight significant changes (new files, deleted files, renamed files)
* Provide context about the branches each worktree contains
| Mode | Description | Command Pattern |
|---|---|---|
| File diff | Compare single file between worktrees | diff -u <wt1>/file <wt2>/file |
| Directory diff | Compare directories recursively | diff -r <wt1>/dir <wt2>/dir |
| Summary only | Show which files differ (no content) | diff -rq <wt1>/ <wt2>/ |
| Git diff | Use git's diff (branch-based) | git diff branch1..branch2 -- path |
The command finds worktrees using git worktree list:
/home/user/project abc1234 [main]
/home/user/project-feature def5678 [feature-x]
/home/user/project-hotfix ghi9012 [hotfix-123]
From this output, the command extracts:
Compare specific file between worktrees:
> /git:compare-worktrees src/app.js
# Prompts to select which worktree to compare with
# Shows diff of src/app.js between current and selected worktree
Compare between two specific worktrees:
> /git:compare-worktrees ../project-main ../project-feature src/module.js
# Compares src/module.js between the two specified worktrees
Compare multiple files/directories:
> /git:compare-worktrees src/app.js src/utils/ package.json
# Shows diffs for all three paths between worktrees
Compare entire directories:
> /git:compare-worktrees src/
# Shows all differences in src/ directory between worktrees
Get summary statistics:
> /git:compare-worktrees --stat
# Shows which files differ and line counts
Interactive mode:
> /git:compare-worktrees
# Lists available worktrees
# Asks which to compare
# Asks for specific paths or entire worktree
Compare with branch worktree by branch name:
> /git:compare-worktrees feature-x
# Finds worktree for feature-x branch and compares
Compare specific paths between branch worktrees:
> /git:compare-worktrees main feature-x src/ tests/
# Compares src/ and tests/ directories between main and feature-x worktrees
File Comparison Header:
Comparing: src/app.js
From: /home/user/project (main)
To: /home/user/project-feature (feature-x)
---
[diff output]
Summary Output:
Worktree Comparison Summary
===========================
From: /home/user/project (main)
To: /home/user/project-feature (feature-x)
Files only in main:
- src/deprecated.js
Files only in feature-x:
+ src/new-feature.js
+ src/new-feature.test.js
Files that differ:
~ src/app.js
~ src/utils/helpers.js
~ package.json
Statistics:
3 files changed
2 files added
1 file removed
# See what changed in a feature branch
> /git:compare-worktrees --stat
> /git:compare-worktrees src/components/
# Compare how two features implemented similar functionality
> /git:compare-worktrees ../project-feature-1 ../project-feature-2 src/auth/
# Check if a specific file differs
> /git:compare-worktrees package.json
# Review all changes before merging (compare src and tests together)
> /git:compare-worktrees --stat
> /git:compare-worktrees src/ tests/
# Both src/ and tests/ directories will be compared
Argument detection : The command auto-detects argument types by comparing them against git worktree list output:
Multiple paths : When multiple file/directory paths are provided, ALL of them are compared between the selected worktrees (not just the first one).
Worktree paths : When specifying worktrees, use the full path or relative path from current directory (e.g., ../project-feature)
Branch vs Worktree : If you specify a branch name, the command looks for a worktree with that branch checked out. If no worktree exists for that branch, it suggests using git diff instead.
Large diffs : For large directories, the command will offer to show a summary first before displaying full diff output.
Binary files : Binary files are detected and reported as "Binary files differ" without showing actual diff.
File permissions : The diff will also show changes in file permissions if they differ.
Use /git:create-worktree first to set up worktrees for comparison:
# Create worktrees for comparison
> /git:create-worktree feature-x, main
# Created: ../project-feature-x and ../project-main
# Now compare
> /git:compare-worktrees src/
"No other worktrees found"
/git:create-worktree <branch>git diff for branch-only comparison without worktrees"Worktree for branch not found"
git worktree list to see available worktrees/git:create-worktree <branch>"Path does not exist in worktree"
Weekly Installs
214
Repository
GitHub Stars
699
First Seen
Feb 19, 2026
Installed on
opencode208
github-copilot207
codex207
gemini-cli206
kimi-cli204
cursor204
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
109,600 周安装
OpenAI API 完整文档技能 - 官方文档集成与智能问答助手
1 周安装
Next.js 官方文档中文指南 - 从入门到精通,掌握App Router、数据获取与性能优化
1 周安装
Hono 框架中文文档 | 轻量级 Web 框架,支持 Bun、Deno、Cloudflare Workers
1 周安装
Express.js 全面中文文档与 API 参考 | 涵盖安全漏洞、性能优化与迁移指南
1 周安装
Drizzle ORM 完整文档 | 无头 ORM 与类 SQL 查询指南
1 周安装
Cortex 文档大全 | 集成指南与 API 参考 | 涵盖 FireHydrant、ServiceNow、Datadog 等
1 周安装
| Show change statistics |
git diff --stat branch1..branch2 |
No worktrees : If no other worktrees exist, the command will explain how to create one and offer to use git diff for branch comparison instead.