resolve-merge-conflicts

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Resolve Merge Conflicts

解决合并冲突

Overview

概述

Resolve conflicts without opening full files unless the compact view is insufficient. Start with a summary, then inspect one conflicted file at a time.
无需打开完整文件即可解决冲突,仅在精简视图不足以处理时再查看完整文件。先从汇总信息入手,再逐个检查存在冲突的文件。

Workflow

工作流程

  1. Start with a summary.
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py
Use the summary to identify which files are unresolved, which index stages exist, and how many text hunks each file contains.
  1. Drill into one file.
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --file path/to/file
Prefer this over reading the whole file. The script prints only nearby context, the
ours
/
base
/
theirs
sections for each hunk, and a compact unified diff between
ours
and
theirs
.
  1. Resolve the file.
  • Take one side wholesale with
    git checkout --ours -- path/to/file
    or
    git checkout --theirs -- path/to/file
    when appropriate.
  • Otherwise edit the file directly and remove the conflict markers.
  • Read more of the file only if the compact output is not enough to decide the correct merge.
  1. Re-check unresolved files.
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py
git diff --name-only --diff-filter=U
  1. Validate the resolution.
  • Ensure no unmerged paths remain.
  • Ensure no
    <<<<<<<
    ,
    =======
    , or
    >>>>>>>
    markers remain in the resolved files.
  • Run targeted tests, builds, or linters for the touched area.
  • Stage the resolved files.
  1. 先查看汇总信息。
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py
通过汇总信息识别哪些文件未解决、存在哪些索引阶段,以及每个文件包含多少文本代码块。
  1. 深入查看单个文件。
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --file path/to/file
优先使用此方式而非读取完整文件。该脚本仅打印冲突附近的上下文、每个代码块的
ours
/
base
/
theirs
部分,以及
ours
theirs
之间的精简统一差异。
  1. 解决文件冲突。
  • 在合适的情况下,使用
    git checkout --ours -- path/to/file
    git checkout --theirs -- path/to/file
    直接采用某一方的内容。
  • 否则直接编辑文件并移除冲突标记。
  • 仅当精简输出不足以确定正确合并方式时,才读取更多文件内容。
  1. 重新检查未解决的文件。
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py
git diff --name-only --diff-filter=U
  1. 验证冲突解决结果。
  • 确保没有剩余未合并路径。
  • 确保已解决的文件中不存在
    <<<<<<<
    =======
    >>>>>>>
    标记。
  • 针对修改区域运行定向测试、构建或代码检查。
  • 暂存已解决的文件。

Commands

命令

Summary only

仅查看汇总信息

bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py

Detailed view for one file

查看单个文件的详细信息

bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --file path/to/file
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --file path/to/file

Detailed view for all conflicted files

查看所有冲突文件的详细信息

bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --all
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --all

JSON output

JSON格式输出

bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --file path/to/file --json
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py --file path/to/file --json

Tune output size

调整输出内容长度

bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py \
  --file path/to/file \
  --context 3 \
  --max-lines 60
bash
python3 .agents/skills/resolve-merge-conflicts/scripts/extract_conflict_context.py \
  --file path/to/file \
  --context 3 \
  --max-lines 60

Notes

注意事项

  • Use the script before opening conflicted files directly.
  • Resolve one file at a time to keep context small.
  • Expect marker-based text conflicts and index-only conflicts such as add/add or modify/delete. The script summarizes both, and it falls back to index-stage previews when the worktree file has no conflict markers.
  • 在直接打开冲突文件前先使用该脚本。
  • 逐个解决文件冲突,以保持上下文简洁。
  • 可能遇到基于标记的文本冲突和仅索引冲突(如添加/添加或修改/删除)。该脚本会汇总这两种冲突,当工作区文件无冲突标记时,会回退到索引阶段预览。