AgentSkillsCN

Git Conflict Resolver

Git 冲突解决器

SKILL.md

Skill: git-conflict-resolver

Purpose

Autonomously handle most git merge conflicts by understanding the semantic intent of the conflicting code changes.

When to Use

  • When git merge main or git rebase main fails with conflicts.
  • As a pre-flight check before starting work on a long-running feature branch.

How It Works

This skill delegates conflict resolution to a MergeConflict Sub-Agent.

Step 1: Attempt the Merge

bash
git fetch origin main
git merge origin/main

If this succeeds, no further action is needed.

Step 2: If Conflicts Occur, Invoke the Sub-Agent

bash
# Get list of conflicted files
CONFLICTED_FILES=$(git diff --name-only --diff-filter=U)

# For each conflicted file, invoke the sub-agent
for FILE in $CONFLICTED_FILES; do
  claude --print "You are a MergeConflict sub-agent. Your task is to resolve the merge conflict in the following file.

**File:** $FILE

**Conflict Markers:**
$(cat $FILE)

**Your Task:**
1. Understand the intent of the changes on BOTH sides of the conflict.
2. Determine the correct resolution that preserves the intent of both changes.
3. Output the resolved file content WITHOUT any conflict markers.

**Rules:**
- Do NOT simply choose one side. Merge the logic if possible.
- If the conflict is too complex to resolve automatically, output 'ESCALATE' and explain why.
"
done

Step 3: Apply the Resolution

If the sub-agent outputs resolved code:

  1. Write the resolved content to the file.
  2. Run git add $FILE.
  3. Run the verification gates (lint, test) to ensure the resolution is correct.
  4. If verification passes, run git commit -m "chore: resolve merge conflict in $FILE".

Step 4: Escalate Complex Conflicts

If the sub-agent outputs ESCALATE:

  1. Log the conflict to progress.txt:
    markdown
    ## [Date] - Merge Conflict Escalation
    - **File**: src/services/UserService.ts
    - **Reason**: Conflicting refactors on both branches. Cannot determine correct merge without human input.
    
  2. Mark the current story as blocked-merge.
  3. Run git merge --abort to restore the branch to a clean state.
  4. Move on to the next story.

Configuration

Add the following to your CLAUDE.md:

markdown
## Git Conflict Resolution

- **Strategy**: merge (or rebase)
- **Auto-Resolve**: Enabled for simple conflicts.
- **Escalation Threshold**: Conflicts involving more than 50 lines or structural changes.