npx skills add https://github.com/antinomyhq/forge --skill resolve-conflicts通过智能合并两个分支的变更来解决 Git 合并冲突,同时保留双方变更的意图。此技能遵循先计划后执行的方法:评估冲突、创建详细的解决计划、获取批准,然后执行。
运行初始检查以了解冲突范围:
git status
识别并分类所有冲突文件:
对于每个冲突文件,收集信息:
根据评估结果,在解决任何冲突之前创建一个结构化的计划。以以下 Markdown 格式呈现计划:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
## 合并解决计划
### 冲突摘要
- **冲突文件总数**:[N]
- **删除-修改冲突**:[N]
- **生成的文件**:[N]
- **常规冲突**:[N]
### 按文件解决的策略
#### 1. [文件路径]
**冲突类型**:[deleted-modified / generated / imports / tests / code logic / config / struct / binary]
**策略**:[解决方案方法的简要描述]
**理由**:[为什么此策略是合适的]
**风险**:[低/中/高] - [简要的风险描述]
**待办事项**:
- [ ] [具体操作 1]
- [ ] [具体操作 2]
#### 2. [文件路径]
...
### 执行顺序
1. **阶段 1:删除-修改文件** - 首先处理删除和备份
2. **阶段 2:生成的文件** - 从源文件重新生成
3. **阶段 3:低风险合并** - 导入、测试、文档
4. **阶段 4:高风险合并** - 代码逻辑、配置、结构体
5. **阶段 5:验证** - 编译、测试、验证
### 需要的问题/决策
- [ ] **[文件/决策]**:[向用户提出的问题](选项:1, 2, 3)
### 验证步骤
- [ ] 运行冲突验证脚本
- [ ] 编译项目
- [ ] 运行测试套件
- [ ] 手动验证高风险更改
将此计划呈现给用户,并在继续解决之前等待他们的批准。如果有任何不明确的冲突需要用户输入,请将其列在"需要的问题/决策"部分。
有关完整示例计划,请参阅 references/sample-plan.md。
仅在计划获得批准后执行此阶段。
如果有删除但被修改的文件(状态:DU, UD, DD, UA, AU):
.forge/skills/resolve-conflicts/scripts/handle-deleted-modified.sh
此脚本将:
查看备份目录和分析文件以了解应将更改应用到哪里。
遵循计划中定义的执行顺序。 对于每个冲突文件,根据您的计划应用适当的解决模式。对于您解决的每个冲突,提供一行解释说明您如何解决它。
当您完成计划中的每个待办事项时,将其标记为已完成并向用户报告进度。
当您无法仅从差异中确定正确的解决方案时(这些应该已经列在您计划的"需要的问题/决策"部分中):
示例交互:
我在 src/main.rs 中发现一个冲突,两个分支都修改了 `calculate_price` 函数:
<<<<<<< HEAD (当前分支)
fn calculate_price(item: &Item) -> f64 {
item.base_price * (1.0 + item.tax_rate)
}
=======
fn calculate_price(item: &Item) -> f64 {
item.base_price + item.tax_amount
}
>>>>>>> feature-branch (传入分支)
我不确定哪个计算是正确的。请选择一个选项:
**选项 1**:保留当前分支(将 base_price 乘以 tax_rate)
**选项 2**:保留传入分支(将 tax_amount 加到 base_price)
**选项 3**:保留两种方法并添加新参数
**选项 4**:提供更多上下文以帮助我决定
请回复"选项 1"、"选项 2"、"选项 3"或"选项 4",或提供额外信息。
用户回复后,应用他们的决定,并将类似的逻辑应用于相关冲突。
对于每个冲突文件,应用适当的解决模式:
目标:合并两个分支中的所有唯一导入。
一行解释:"通过合并两个分支中的唯一导入、移除重复项并按模块分组来合并导入。"
阅读 references/patterns.md 中的"导入冲突"部分以获取详细示例。
快速方法:
目标:包含两个分支中的所有测试用例和测试数据。
一行解释:"通过包含两个分支中的所有测试用例、合并夹具并在必要时重命名以避免冲突来合并测试。"
阅读 references/patterns.md 中的"测试冲突"部分以获取详细示例。
快速方法:
目标:重新生成任何生成的文件以包含两个分支的更改。
一行解释:"通过从源文件重新生成以合并两个分支的更改来解决生成的文件。"
识别:如果文件满足以下条件,则它是生成的:
.gitattributes 中列为生成的文件方法:
识别生成源:确定生成文件的命令或工具
临时选择任一版本(选择哪个版本并不重要):
git checkout --ours <generated-file> # 或 --theirs
从源重新生成:运行适当的生成命令:
# 包管理器锁定文件
cargo update # 用于 Cargo.lock
npm install # 用于 package-lock.json
yarn install # 用于 yarn.lock
bundle install # 用于 Gemfile.lock
poetry lock --no-update # 用于 poetry.lock
# 代码生成
protoc ... # 用于 protobuf 文件
graphql-codegen # 用于 GraphQL 生成的代码
make generate # 用于基于 Makefile 的生成
npm run generate # 用于基于 npm 脚本的生成
# 构建产物
npm run build # 用于编译/打包的资源
cargo build # 用于 Rust 构建产物
暂存重新生成的文件:
git add <generated-file>
当不确定文件是否生成时:检查文件头中的自动生成标记,或询问用户是应该重新生成还是手动合并该文件。
目标:合并两个分支的配置值。
一行解释:"通过包含两个分支中的所有键并为冲突选择适当的值来合并配置。"
阅读 references/patterns.md 中的"配置文件冲突"部分以获取详细示例。
快速方法:
当不明确时:询问用户偏好哪个配置值(当前分支 vs 传入分支)
目标:理解双方更改的意图,并在可能的情况下合并。
一行解释:"通过分析意图来解决代码逻辑:如果更改是正交的则合并,如果冲突则选择一种方法。"
阅读 references/patterns.md 中的"代码逻辑冲突"部分以获取详细示例。
快速方法:
当不明确时:将两种方法作为选项呈现给用户,并附上每种方法作用的上下文
目标:包含两个分支中的所有字段。
一行解释:"通过包含两个分支中的所有字段并为任何冲突的字段定义选择适当的类型来合并结构体。"
快速方法:
当不明确时:如果字段类型冲突,询问用户哪个类型定义是正确的
完成计划中的所有解决阶段后,验证所有冲突是否已解决:
.forge/skills/resolve-conflicts/scripts/validate-conflicts.sh
此脚本检查:
构建和测试以确保解决方案正确(如计划验证步骤中所定义):
# 对于 Rust 项目
cargo test
# 对于其他项目,使用适当的测试命令
# npm test
# pytest
# 等等。
如果测试失败:
一旦所有冲突都解决且测试通过,请查看您完成的计划并提交:
# 查看更改
git diff --cached
# 提交并附上描述性消息,引用计划
git commit -m "解决合并冲突:[描述关键决策]
执行了合并解决计划:
- [阶段 1 摘要]
- [阶段 2 摘要]
- [阶段 3+ 摘要]
关键决策:
- 合并了两个分支的导入
- 合并了测试用例
- 重新生成了锁定文件
- [计划中的其他重要决策]
Co-Authored-By: ForgeCode <noreply@forgecode.dev>"
当您要求用户在选项之间进行选择时,跟踪他们的决定并将类似的推理应用于后续冲突:
示例场景:
关键原则:
有关详细的解决模式,请阅读:
references/patterns.md - 所有冲突类型的综合示例快速模式查找:
二进制文件无法合并。选择一个版本:
git checkout --ours path/to/binary # 保留我们的版本
# 或
git checkout --theirs path/to/binary # 保留他们的版本
如果一个分支重命名/重构了许多文件,而另一个分支修改了它们:
handle-deleted-modified.sh 的备份来指导应用# 检查子模块状态
git submodule status
# 更新到正确的提交
cd path/to/submodule
git checkout <desired-commit>
cd ../..
git add path/to/submodule
两个分支都添加了同名但内容不同的新文件:
如果冲突仅由空格差异引起:
git merge -Xignore-space-change <branch>
如果验证显示冲突标记,但您认为您已经解决了它们:
git grep -n "<<<<<<< HEAD"| 冲突类型 | 策略 | 一行解释模板 |
|---|---|---|
| 导入 | 合并所有,去重,按模块分组 | "通过合并两个分支中的唯一导入并按模块分组来合并导入" |
| 测试 | 保留所有,合并夹具 | "包含两个分支中的所有测试用例并合并测试夹具" |
| 生成的文件 | 从源重新生成 | "从源重新生成 [文件] 以包含两个分支的更改" |
| 配置 | 合并键,选择更新值 | "合并所有配置键并为 [键] 选择 [当前/传入] 值" |
| 代码逻辑 | 分析意图,如果正交则合并 | "合并两个更改,因为它们解决了不同的关注点" 或 "为 [原因] 选择 [当前/传入] 方法" |
| 结构体 | 包含所有字段 | "在结构体定义中包含两个分支中的所有字段" |
| 文档 | 合并所有部分 | "合并两个分支的文档" |
| 删除-修改 | 备份,分析,应用到新位置 | "在文件被移动/重命名后将修改应用到新位置" |
| 二进制文件 | 选择一个版本 | "保留二进制文件的 [当前/传入] 版本" |
记住:
每周安装
90
仓库
GitHub 星标
4.7K
首次出现
Jan 23, 2026
安全审计
安装于
opencode78
codex77
gemini-cli74
cursor74
github-copilot71
claude-code70
Resolve Git merge conflicts by intelligently combining changes from both branches while preserving the intent of both changes. This skill follows a plan-first approach: assess conflicts, create a detailed resolution plan, get approval, then execute.
Run initial checks to understand the conflict scope:
git status
Identify and categorize all conflicted files:
For each conflicted file, gather information:
Based on the assessment, create a structured plan before resolving any conflicts. Present the plan in the following markdown format:
## Merge Resolution Plan
### Conflict Summary
- **Total conflicted files**: [N]
- **Deleted-modified conflicts**: [N]
- **Generated files**: [N]
- **Regular conflicts**: [N]
### Resolution Strategy by File
#### 1. [File Path]
**Conflict Type**: [deleted-modified / generated / imports / tests / code logic / config / struct / binary]
**Strategy**: [Brief description of resolution approach]
**Rationale**: [Why this strategy is appropriate]
**Risk**: [Low/Medium/High] - [Brief risk description]
**Action Items**:
- [ ] [Specific action 1]
- [ ] [Specific action 2]
#### 2. [File Path]
...
### Execution Order
1. **Phase 1: Deleted-Modified Files** - Handle deletions and backups first
2. **Phase 2: Generated Files** - Regenerate from source
3. **Phase 3: Low-Risk Merges** - Imports, tests, documentation
4. **Phase 4: High-Risk Merges** - Code logic, configuration, structs
5. **Phase 5: Validation** - Compile, test, verify
### Questions/Decisions Needed
- [ ] **[File/Decision]**: [Question for user] (Options: 1, 2, 3)
### Validation Steps
- [ ] Run conflict validation script
- [ ] Compile project
- [ ] Run test suite
- [ ] Manual verification of high-risk changes
Present this plan to the user and wait for their approval before proceeding with resolution. If there are any unclear conflicts where you need user input, list them in the "Questions/Decisions Needed" section.
For a complete example plan , see references/sample-plan.md.
Execute this phase only after the plan is approved.
If there are deleted-but-modified files (status: DU, UD, DD, UA, AU):
.forge/skills/resolve-conflicts/scripts/handle-deleted-modified.sh
This script will:
Review the backup directory and analysis files to understand where changes should be applied.
Follow the execution order defined in your plan. For each conflicted file, apply the appropriate resolution pattern according to your plan. For every conflict you resolve, provide a one-line explanation of how you're resolving it.
As you complete each action item in your plan, mark it as done and report progress to the user.
When you cannot determine the correct resolution from the diff alone (these should already be listed in your plan's "Questions/Decisions Needed" section):
Example interaction:
I found a conflict in src/main.rs where both branches modify the `calculate_price` function:
<<<<<<< HEAD (Current Branch)
fn calculate_price(item: &Item) -> f64 {
item.base_price * (1.0 + item.tax_rate)
}
=======
fn calculate_price(item: &Item) -> f64 {
item.base_price + item.tax_amount
}
>>>>>>> feature-branch (Incoming Branch)
I'm not sure which calculation is correct. Please select an option:
**Option 1**: Keep current branch (multiplies base_price by tax_rate)
**Option 2**: Keep incoming branch (adds tax_amount to base_price)
**Option 3**: Keep both approaches with a new parameter
**Option 4**: Provide more context to help me decide
Please respond with "Option 1", "Option 2", "Option 3", or "Option 4", or provide additional information.
Once the user responds, apply their decision and similar logic to related conflicts.
For each conflicted file, apply the appropriate resolution pattern:
Goal : Merge all unique imports from both branches.
One-line explanation : "Merging imports by combining unique imports from both branches, removing duplicates, and grouping by module."
Read references/patterns.md section "Import Conflicts" for detailed examples.
Quick approach:
Goal : Include all test cases and test data from both branches.
One-line explanation : "Merging tests by including all test cases from both branches, combining fixtures, and renaming if necessary to avoid conflicts."
Read references/patterns.md section "Test Conflicts" for detailed examples.
Quick approach:
Goal : Regenerate any generated files to include changes from both branches.
One-line explanation : "Resolving generated file by regenerating it from source files to incorporate changes from both branches."
Recognition : A file is generated if it:
.gitattributes as generatedApproach:
Identify the generation source : Determine what command or tool generates the file
Choose either version temporarily (doesn't matter which):
git checkout --ours <generated-file> # or --theirs
Regenerate from source : Run the appropriate generation command:
# Package manager lock files
cargo update # for Cargo.lock
npm install # for package-lock.json
yarn install # for yarn.lock
bundle install # for Gemfile.lock
poetry lock --no-update # for poetry.lock
# Code generation
protoc ... # for protobuf files
graphql-codegen # for GraphQL generated code
make generate # for Makefile-based generation
npm run generate # for npm script-based generation
# Build artifacts
npm run build # for compiled/bundled assets
cargo build # for Rust build artifacts
Stage the regenerated file :
git add <generated-file>
When unsure if a file is generated : Check for auto-generation markers in the file header, or ask the user if you should regenerate or manually merge the file.
Goal : Merge configuration values from both branches.
One-line explanation : "Merging configuration by including all keys from both branches and choosing appropriate values for conflicts."
Read references/patterns.md section "Configuration File Conflicts" for detailed examples.
Quick approach:
When unclear : Ask the user which configuration value to prefer (current vs incoming)
Goal : Understand intent of both changes and combine if possible.
One-line explanation : "Resolving code logic by analyzing intent: merging if changes are orthogonal, or choosing one approach if they conflict."
Read references/patterns.md section "Code Logic Conflicts" for detailed examples.
Quick approach:
When unclear : Present both approaches as options to the user with context about what each does
Goal : Include all fields from both branches.
One-line explanation : "Merging struct by including all fields from both branches and choosing appropriate types for any conflicting field definitions."
Quick approach:
When unclear : Ask the user which type definition is correct if field types conflict
After completing all resolution phases in your plan, validate that all conflicts are resolved:
.forge/skills/resolve-conflicts/scripts/validate-conflicts.sh
This script checks for:
Build and test to ensure the resolution is correct (as defined in your plan's validation steps):
# For Rust projects
cargo test
# For other projects, use appropriate test command
# npm test
# pytest
# etc.
If tests fail:
Once all conflicts are resolved and tests pass, review your completed plan and commit:
# Review the changes
git diff --cached
# Commit with descriptive message that references the plan
git commit -m "Resolve merge conflicts: [describe key decisions]
Executed merge resolution plan:
- [Phase 1 summary]
- [Phase 2 summary]
- [Phase 3+ summaries]
Key decisions:
- Merged imports from both branches
- Combined test cases
- Regenerated lock files
- [other significant decisions from plan]
Co-Authored-By: ForgeCode <noreply@forgecode.dev>"
When you ask the user to choose between options, track their decision and apply similar reasoning to subsequent conflicts:
Example scenario:
Key principles:
For detailed resolution patterns, read:
references/patterns.md - Comprehensive examples for all conflict typesQuick pattern lookup:
Binary files cannot be merged. Choose one version:
git checkout --ours path/to/binary # keep our version
# or
git checkout --theirs path/to/binary # keep their version
If one branch renamed/refactored many files while another modified them:
handle-deleted-modified.sh to guide the application# Check submodule status
git submodule status
# Update to the correct commit
cd path/to/submodule
git checkout <desired-commit>
cd ../..
git add path/to/submodule
Both branches added a new file with the same name but different content:
If conflicts are only whitespace differences:
git merge -Xignore-space-change <branch>
If validation shows conflict markers but you think you resolved them:
git grep -n "<<<<<<< HEAD"| Conflict Type | Strategy | One-line Explanation Template |
|---|---|---|
| Imports | Merge all, deduplicate, group by module | "Merging imports by combining unique imports from both branches and grouping by module" |
| Tests | Keep all, merge fixtures | "Including all test cases from both branches and combining test fixtures" |
| Generated files | Regenerate from source | "Regenerating [file] from source to include changes from both branches" |
| Config | Merge keys, choose newer values | "Merging all config keys and choosing [current/incoming] value for [key]" |
| Code logic | Analyze intent, merge if orthogonal | "Merging both changes as they address different concerns" OR "Choosing [current/incoming] approach for [reason]" |
| Structs | Include all fields | "Including all fields from both branches in struct definition" |
| Docs | Combine all sections | "Combining documentation from both branches" |
| Deleted-modified | Backup, analyze, apply to new location |
Remember:
Weekly Installs
90
Repository
GitHub Stars
4.7K
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
opencode78
codex77
gemini-cli74
cursor74
github-copilot71
claude-code70
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
152,900 周安装
OpenClaw 环境安全审计员:一键扫描密钥泄露,审计沙箱配置,保障AI技能运行安全
135 周安装
OpenViking 记忆插件指南:AI助手长期记忆管理与自动上下文注入
135 周安装
ByteRover CLI - 上下文工程平台,为AI编码智能体自动管理项目知识库
135 周安装
Symfony API Platform序列化指南:合约设计、安全防护与渐进式披露
135 周安装
PostgreSQL只读查询技能 - 安全连接AI助手执行数据库查询,支持SSL加密与权限控制
135 周安装
Next.js服务端与客户端组件选择指南:TypeScript最佳实践与性能优化
135 周安装
| "Applying modifications to new location after file was moved/renamed" |
| Binary files | Choose one version | "Keeping [current/incoming] version of binary file" |