xiaohongshu
xiaohongshu
conflict-resolve
Guided conflict resolution with semantic analysis and validation
Full skill instructions
I'll help you resolve merge conflicts with semantic analysis and intelligent strategy recommendations.
Arguments: $ARGUMENTS - strategy (ours/theirs/manual) or file path
Resolve conflicts intelligently:
/test skillThis skill uses conflict resolution-specific patterns to minimize token usage:
Pattern: Cache conflict detection and file lists
.conflict-resolve-cache (5 min TTL)Pattern: Detect no-conflict state immediately
Pattern: Use git commands for conflict detection
git diff --name-only --diff-filter=U (100 tokens)git diff --check (100 tokens)Pattern: Analyze first 5 conflicted files in detail
Pattern: Use predefined resolution patterns
Pattern: Resolve one file at a time, not all at once
Pattern: Find conflict markers with Grep
<<<<<<<, =======, >>>>>>> (150 tokens)Pattern: Run minimal tests after resolution
Typical operation patterns:
Expected per-resolution: 1,500-2,500 tokens (50% reduction from 3,000-5,000 baseline) Real-world average: 1,000 tokens (due to early exit, sample analysis, incremental resolution)
Before resolving conflicts, I'll verify:
First, let me detect and analyze conflicts:
#!/bin/bash
# Detect and analyze merge conflicts
set -e
echo "=== Conflict Detection ==="
echo ""
# 1. Verify git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Error: Not a git repository"
exit 1
fi
# 2. Check if merge/rebase in progress
merge_in_progress=0
rebase_in_progress=0
if [ -f "$(git rev-parse --git-dir)/MERGE_HEAD" ]; then
merge_in_progress=1
echo "Status: Merge in progress"
elif [ -d "$(git rev-parse --git-dir)/rebase-merge" ] || [ -d "$(git rev-parse --git-dir)/rebase-apply" ]; then
rebase_in_progress=1
echo "Status: Rebase in progress"
else
echo "Status: No merge or rebase in progress"
echo ""
echo "No conflicts to resolve"
exit 0
fi
echo ""
# 3. List conflicted files
echo "Conflicted Files:"
conflicted_files=$(git diff --name-only --diff-filter=U)
if [ -z "$conflicted_files" ]; then
echo " No conflicted files found"
exit 0
fi
echo "$conflicted_files" | while read -r file; do
echo " • $file"
done
echo ""
# 4. Count conflicts
conflict_count=$(echo "$conflicted_files" | wc -l)
echo "Total Conflicts: $conflict_count"
echo ""
# 5. Categorize conflicts
echo "Conflict Categories:"
echo "$conflicted_files" | awk -F'/' '{
if ($0 ~ /test/) tests++
else if ($0 ~ /\.(md|txt)$/) docs++
else if ($0 ~ /\.(ts|js|tsx|jsx)$/) code++
else if ($0 ~ /\.(yml|yaml|json|lock)$/) config++
else if ($0 ~ /package\.json|requirements\.txt|Cargo\.toml/) deps++
else others++
}
END {
if (code) print " Code files: " code
if (config) print " Config files: " config
if (deps) print " Dependencies: " deps
if (tests) print " Test files: " tests
if (docs) print " Documentation: " docs
if (others) print " Other: " others
}'
echo ""
# 6. Show branches involved
if [ $merge_in_progress -eq 1 ]; then
echo "Merge Details:"
echo " Current: $(git branch --show-current)"
echo " Merging: $(git rev-parse --abbrev-ref MERGE_HEAD)"
elif [ $rebase_in_progress -eq 1 ]; then
echo "Rebase Details:"
echo " Onto: $(cat "$(git rev-parse --git-dir)/rebase-merge/onto" 2>/dev/null || echo "unknown")"
fi
echo ""
Understand the nature of each conflict:
#!/bin/bash
# Analyze conflict complexity
analyze_conflict() {
local file="$1"
echo "=== Analyzing: $file ==="
echo ""
# 1. Count conflict markers
conflict_sections=$(grep -c "^<<<<<<< " "$file" 2>/dev/null || echo "0")
echo "Conflict Sections: $conflict_sections"
echo ""
# 2. Show conflict context
echo "Conflicts in $file:"
echo "----------------------------------------"
# Extract and display each conflict
awk '
/^<<<<<<< / { in_conflict=1; ours="" }
/^=======/ { in_ours=0; in_theirs=1 }
/^>>>>>>> / {
in_conflict=0
in_theirs=0
conflicts++
print ""
next
}
in_conflict && !in_theirs {
if ($0 !~ /^<<<<<<< /) ours = ours $0 "\n"
}
in_theirs {
if ($0 !~ /^=======/ && $0 !~ /^>>>>>>> /) {
print "OURS (" conflicts+1 "):"
print ours
print "THEIRS (" conflicts+1 "):"
print $0
while (getline > 0 && $0 !~ /^>>>>>>> /) {
if ($0 !~ /^=======/) print $0
}
print "---"
}
}
' "$file"
echo "----------------------------------------"
echo ""
# 3. Detect conflict type
if grep -q "package.json\|package-lock.json\|yarn.lock" <<< "$file"; then
echo "Type: Dependency conflict"
echo "Strategy: Accept theirs, then reinstall"
elif grep -q "\.md$\|\.txt$\|README" <<< "$file"; then
echo "Type: Documentation conflict"
echo "Strategy: Manual merge (both changes likely valid)"
elif grep -q "test" <<< "$file"; then
echo "Type: Test conflict"
echo "Strategy: Keep both, ensure tests pass"
else
echo "Type: Code conflict"
echo "Strategy: Semantic analysis required"
fi
echo ""
}
# Analyze first conflicted file
first_conflict=$(echo "$conflicted_files" | head -1)
analyze_conflict "$first_conflict"
Recommend the best resolution strategy:
Now I'll recommend a resolution strategy:
#!/bin/bash
# Recommend resolution strategy
recommend_strategy() {
local file="$1"
echo "=== Resolution Strategy ==="
echo ""
# Analyze file content
file_type=$(basename "$file")
# Strategy matrix
case "$file" in
package.json|package-lock.json|yarn.lock|Gemfile.lock|Cargo.lock)
echo "Recommended: Accept THEIRS + Reinstall"
echo "Reason: Dependency locks should be regenerated"
echo ""
echo "Steps:"
echo " 1. git checkout --theirs $file"
echo " 2. npm install / bundle install / cargo build"
echo " 3. git add $file"
strategy="theirs-reinstall"
;;
*.md|*.txt|README*|CHANGELOG*)
echo "Recommended: MANUAL merge"
echo "Reason: Documentation - both changes likely valid"
echo ""
echo "Steps:"
echo " 1. Edit file manually"
echo " 2. Combine both versions"
echo " 3. Remove conflict markers"
echo " 4. git add $file"
strategy="manual"
;;
*test*|*spec*)
echo "Recommended: Keep BOTH + Validate"
echo "Reason: Tests - both may be needed"
echo ""
echo "Steps:"
echo " 1. Merge both test cases"
echo " 2. Ensure tests run"
echo " 3. git add $file"
strategy="both"
;;
*.json|*.yml|*.yaml|*.toml)
echo "Recommended: MANUAL with validation"
echo "Reason: Config files - semantic meaning important"
echo ""
echo "Steps:"
echo " 1. Edit carefully"
echo " 2. Validate syntax"
echo " 3. git add $file"
strategy="manual-validate"
;;
*)
echo "Recommended: SEMANTIC analysis"
echo "Reason: Code conflict - need to understand both changes"
echo ""
echo "I'll analyze both versions..."
strategy="semantic"
;;
esac
echo ""
echo "Strategy: $strategy"
}
recommend_strategy "$first_conflict"
For code conflicts, analyze both versions:
For code conflicts, I'll perform semantic analysis:
#!/bin/bash
# Semantic conflict analysis
semantic_analysis() {
local file="$1"
echo "=== Semantic Analysis ==="
echo ""
# Extract OURS version
echo "Extracting versions..."
git show :2:"$file" > "/tmp/conflict-ours.tmp" 2>/dev/null || true
git show :3:"$file" > "/tmp/conflict-theirs.tmp" 2>/dev/null || true
# Compare versions
echo "Version Comparison:"
echo ""
echo "OURS (current branch):"
echo "----------------------------------------"
head -20 "/tmp/conflict-ours.tmp" || echo "Cannot extract OURS"
echo "----------------------------------------"
echo ""
echo "THEIRS (incoming changes):"
echo "----------------------------------------"
head -20 "/tmp/conflict-theirs.tmp" || echo "Cannot extract THEIRS"
echo "----------------------------------------"
echo ""
# Analyze differences
echo "Key Differences:"
diff -u "/tmp/conflict-ours.tmp" "/tmp/conflict-theirs.tmp" | head -30 || true
echo ""
# Cleanup
rm -f "/tmp/conflict-ours.tmp" "/tmp/conflict-theirs.tmp"
}
if [ "$strategy" = "semantic" ]; then
semantic_analysis "$first_conflict"
fi
Guide through manual resolution:
I'll guide you through resolving this conflict:
Option 1: Accept OURS (current branch)
git checkout --ours <file>
git add <file>
Option 2: Accept THEIRS (incoming changes)
git checkout --theirs <file>
git add <file>
Option 3: Manual Edit
<<<<<<< HEAD (ours)
your changes
=======
their changes
>>>>>>> branch-name (theirs)
Option 4: Use Merge Tool
git mergetool
Let me help you resolve this step by step:
#!/bin/bash
# Interactive conflict resolution
resolve_interactive() {
local file="$1"
local strategy="${2:-ask}"
echo "=== Resolving: $file ==="
echo ""
if [ "$strategy" = "ours" ]; then
echo "Accepting OURS (current branch)..."
git checkout --ours "$file"
git add "$file"
echo "✓ Resolved with OURS"
elif [ "$strategy" = "theirs" ]; then
echo "Accepting THEIRS (incoming changes)..."
git checkout --theirs "$file"
git add "$file"
echo "✓ Resolved with THEIRS"
elif [ "$strategy" = "manual" ]; then
echo "Opening file for manual edit..."
echo ""
echo "Conflict markers to remove:"
echo " <<<<<<< HEAD"
echo " ======="
echo " >>>>>>> branch-name"
echo ""
# Show conflict sections
grep -n -A3 -B3 "^<<<<<<< \|^=======\|^>>>>>>> " "$file" | head -30
echo ""
echo "After editing:"
echo " 1. Save file"
echo " 2. Verify no conflict markers remain"
echo " 3. Run: git add $file"
elif [ "$strategy" = "ask" ]; then
echo "Choose resolution:"
echo " 1. Accept OURS (current branch)"
echo " 2. Accept THEIRS (incoming changes)"
echo " 3. Manual edit"
echo " 4. Show diff"
echo " 5. Skip this file"
echo ""
read -p "Selection [1-5]: " choice
case $choice in
1) resolve_interactive "$file" "ours" ;;
2) resolve_interactive "$file" "theirs" ;;
3) resolve_interactive "$file" "manual" ;;
4)
git diff "$file"
resolve_interactive "$file" "ask"
;;
5) echo "Skipped: $file" ;;
*) echo "Invalid choice"; resolve_interactive "$file" "ask" ;;
esac
fi
}
# Resolve each conflicted file
echo "$conflicted_files" | while read -r file; do
resolve_interactive "$file" "${ARGUMENTS}"
echo ""
done
Validate conflict resolution:
#!/bin/bash
# Validate conflict resolution
validate_resolution() {
echo "=== Validation ==="
echo ""
# 1. Check for remaining conflict markers
echo "1. Checking for conflict markers..."
if git diff --check 2>&1 | grep -q "conflict"; then
echo " ⚠ Conflict markers still present"
git diff --check
return 1
else
echo " ✓ No conflict markers"
fi
echo ""
# 2. Check if all conflicts resolved
echo "2. Checking for unresolved conflicts..."
unresolved=$(git diff --name-only --diff-filter=U)
if [ -n "$unresolved" ]; then
echo " ⚠ Unresolved conflicts:"
echo "$unresolved"
return 1
else
echo " ✓ All conflicts resolved"
fi
echo ""
# 3. Validate file syntax
echo "3. Syntax validation..."
for file in $(git diff --name-only --cached); do
case "$file" in
*.json)
if command -v jq > /dev/null 2>&1; then
if jq empty "$file" 2>/dev/null; then
echo " ✓ $file - valid JSON"
else
echo " ✗ $file - invalid JSON"
return 1
fi
fi
;;
*.yml|*.yaml)
if command -v yamllint > /dev/null 2>&1; then
if yamllint "$file" 2>/dev/null; then
echo " ✓ $file - valid YAML"
else
echo " ⚠ $file - YAML warnings"
fi
fi
;;
package.json)
if command -v npm > /dev/null 2>&1; then
if npm install --package-lock-only 2>/dev/null; then
echo " ✓ package.json - dependencies valid"
else
echo " ✗ package.json - dependency issues"
return 1
fi
fi
;;
esac
done
echo ""
# 4. Build check
echo "4. Build verification..."
if [ -f "package.json" ] && grep -q "\"build\":" package.json; then
if npm run build > /dev/null 2>&1; then
echo " ✓ Build successful"
else
echo " ⚠ Build failed"
echo " Review resolved files"
return 1
fi
else
echo " ⓘ No build command found"
fi
echo ""
# 5. Test check
echo "5. Test verification..."
if [ -f "package.json" ] && grep -q "\"test\":" package.json; then
echo " Running tests..."
if npm test 2>&1 | tail -10; then
echo " ✓ Tests passing"
else
echo " ⚠ Tests failing"
echo " Conflict resolution may need adjustment"
return 1
fi
else
echo " ⓘ No test command found"
fi
echo ""
echo "✓ All validations passed"
return 0
}
validate_resolution
Finalize the merge/rebase:
#!/bin/bash
# Complete merge or rebase
complete_resolution() {
echo "=== Complete Resolution ==="
echo ""
# Check resolution type
if [ -f "$(git rev-parse --git-dir)/MERGE_HEAD" ]; then
echo "Completing merge..."
# Show what will be committed
echo "Changes to commit:"
git diff --cached --stat
echo ""
# Generate merge commit message
merge_msg="Merge branch '$(git rev-parse --abbrev-ref MERGE_HEAD)'"
echo "Committing merge..."
git commit -m "$merge_msg" || git commit --no-edit
echo "✓ Merge complete"
elif [ -d "$(git rev-parse --git-dir)/rebase-merge" ] || [ -d "$(git rev-parse --git-dir)/rebase-apply" ]; then
echo "Continuing rebase..."
# Continue rebase
git rebase --continue
echo "✓ Rebase continued"
echo ""
echo "If more conflicts exist, run /conflict-resolve again"
else
echo "No merge or rebase in progress"
fi
}
if validate_resolution; then
complete_resolution
else
echo "⚠ Validation failed"
echo "Fix issues before completing resolution"
exit 1
fi
Common Scenarios:
1. Package Lock Conflicts:
/conflict-resolve theirs
npm install # Regenerate lock
git add package-lock.json
2. Documentation Conflicts:
/conflict-resolve manual
# Edit file to combine both versions
git add README.md
3. Code Conflicts:
/conflict-resolve
# Analyze semantic differences
# Choose appropriate strategy
# Validate with tests
4. Config Conflicts:
/conflict-resolve manual
# Carefully merge configurations
# Validate syntax
git add config.yml
Complete Workflow:
# 1. Conflict detected during merge/rebase
git merge feature-branch # Conflicts!
# 2. Resolve conflicts
/conflict-resolve
# 3. Validate with tests
/test
# 4. Complete merge
git commit
# Or during branch-finish
/branch-finish # May trigger conflict-resolve
Three-Way Merge:
# Show base, ours, and theirs
git show :1:file # Base (common ancestor)
git show :2:file # Ours (current branch)
git show :3:file # Theirs (incoming)
Merge Tool Integration:
# Configure merge tool
git config merge.tool vimdiff
# Use during resolution
git mergetool <file>
Abort Options:
# Abort merge
git merge --abort
# Abort rebase
git rebase --abort
# Restore original state
git reset --hard ORIG_HEAD
Before Resolution:
During Resolution:
After Resolution:
If resolution fails:
Common Errors:
/test skillImportant: I will NEVER:
Conflict resolution will be safe, validated, and thorough.
Credits: Conflict resolution strategies based on Git best practices, semantic merge techniques, and safe validation workflows.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience