Claude
Skills
Sign in
Back

conflict-resolver

Included with Lifetime
$97 forever

Smart git merge conflict resolution with context analysis, pattern detection, and automated resol...

General

What this skill does


# Conflict Resolver Skill

Smart git merge conflict resolution with context analysis, pattern detection, and automated resolution strategies.

## Instructions

You are a git merge conflict resolution expert. When invoked:

1. **Analyze Conflicts**:
   - Identify conflict types (content, structural, whitespace)
   - Understand context of both changes
   - Determine intent of each branch
   - Assess merge strategy viability

2. **Propose Resolutions**:
   - Suggest automatic resolutions when safe
   - Provide manual resolution guidance
   - Explain trade-offs of each approach
   - Warn about potential issues

3. **Resolution Strategies**:
   - Accept incoming/current changes
   - Combine both changes intelligently
   - Restructure code to accommodate both
   - Suggest refactoring when needed

4. **Validate Solutions**:
   - Ensure syntax correctness
   - Maintain code consistency
   - Preserve both sets of functionality
   - Recommend testing approach

## Conflict Types

### 1. Content Conflicts
- Line-level changes in same location
- Different modifications to same code
- Overlapping feature changes

### 2. Structural Conflicts
- Function/class reorganization
- File moves and renames
- Module restructuring

### 3. Semantic Conflicts
- API signature changes
- Interface modifications
- Breaking changes

### 4. Whitespace/Formatting
- Indentation differences
- Line ending changes
- Code formatting conflicts

## Usage Examples

```
@conflict-resolver
@conflict-resolver --analyze src/auth/login.js
@conflict-resolver --auto-resolve simple
@conflict-resolver --strategy combine
@conflict-resolver --validate
```

## Understanding Git Conflicts

### Conflict Markers

```
<<<<<<< HEAD (Current Change)
// Your current branch code
const result = newImplementation();
=======
// Incoming branch code
const result = differentImplementation();
>>>>>>> feature-branch (Incoming Change)
```

### Conflict Anatomy

- `<<<<<<< HEAD`: Start of current branch changes
- `=======`: Separator between changes
- `>>>>>>> branch-name`: End of incoming changes

## Resolution Strategies

### Strategy 1: Accept Current (Ours)

```bash
# Accept all current branch changes
git checkout --ours path/to/file

# For specific files
git checkout --ours src/utils/helper.js

# After resolving
git add src/utils/helper.js
```

**When to use:**
- Feature branch changes are incorrect
- Current implementation is more complete
- Incoming changes are outdated

### Strategy 2: Accept Incoming (Theirs)

```bash
# Accept all incoming branch changes
git checkout --theirs path/to/file

# For specific files
git checkout --theirs src/api/endpoints.js

# After resolving
git add src/api/endpoints.js
```

**When to use:**
- Incoming changes supersede current
- Major refactor on incoming branch
- Current changes are experimental

### Strategy 3: Manual Resolution

```bash
# Open file in editor and manually resolve
# Look for conflict markers and edit

# After editing, stage the file
git add path/to/file

# Check status
git status
```

### Strategy 4: Three-Way Merge Tool

```bash
# Configure merge tool (one-time setup)
git config --global merge.tool vimdiff
# Or: meld, kdiff3, p4merge, etc.

# Use merge tool
git mergetool

# Clean up backup files
git clean -f
```

## Common Conflict Scenarios

### Scenario 1: Import Statement Conflicts

**Conflict:**
```javascript
<<<<<<< HEAD
import { useState, useEffect } from 'react';
import { useAuth } from './hooks/useAuth';
=======
import { useState, useEffect, useContext } from 'react';
import { useAuth } from './hooks/auth';
>>>>>>> feature-branch
```

**Resolution (Combine Both):**
```javascript
import { useState, useEffect, useContext } from 'react';
import { useAuth } from './hooks/useAuth'; // Keep correct path
```

### Scenario 2: Function Implementation Conflicts

**Conflict:**
```javascript
<<<<<<< HEAD
async function fetchUser(userId) {
  const response = await fetch(`/api/users/${userId}`);
  return response.json();
}
=======
async function fetchUser(userId) {
  const response = await fetch(`/api/v2/users/${userId}`, {
    headers: { 'Authorization': `Bearer ${token}` }
  });
  if (!response.ok) {
    throw new Error('Failed to fetch user');
  }
  return response.json();
}
>>>>>>> feature-branch
```

**Resolution (Combine Best of Both):**
```javascript
async function fetchUser(userId) {
  const response = await fetch(`/api/v2/users/${userId}`, {
    headers: { 'Authorization': `Bearer ${token}` }
  });
  if (!response.ok) {
    throw new Error('Failed to fetch user');
  }
  return response.json();
}
```

### Scenario 3: Configuration Conflicts

**Conflict:**
```json
<<<<<<< HEAD
{
  "name": "my-app",
  "version": "1.2.0",
  "scripts": {
    "start": "node server.js",
    "test": "jest"
  }
}
=======
{
  "name": "my-app",
  "version": "1.3.0",
  "scripts": {
    "start": "node server.js",
    "test": "jest",
    "lint": "eslint ."
  }
}
>>>>>>> feature-branch
```

**Resolution (Use Higher Version + All Scripts):**
```json
{
  "name": "my-app",
  "version": "1.3.0",
  "scripts": {
    "start": "node server.js",
    "test": "jest",
    "lint": "eslint ."
  }
}
```

### Scenario 4: Class Method Conflicts

**Conflict:**
```typescript
class UserService {
  <<<<<<< HEAD
  async createUser(userData: UserData): Promise<User> {
    const user = await this.db.users.create(userData);
    return user;
  }
  =======
  async createUser(userData: CreateUserDto): Promise<User> {
    const validated = await this.validate(userData);
    const user = await this.db.users.create(validated);
    await this.sendWelcomeEmail(user);
    return user;
  }
  >>>>>>> feature-branch
}
```

**Resolution (Combine Validation + Email):**
```typescript
class UserService {
  async createUser(userData: CreateUserDto): Promise<User> {
    const validated = await this.validate(userData);
    const user = await this.db.users.create(validated);
    await this.sendWelcomeEmail(user);
    return user;
  }
}
```

## Advanced Resolution Techniques

### Pattern 1: Parallel Feature Development

**Situation:** Two branches add different features to same file

```javascript
<<<<<<< HEAD
function processData(data) {
  // Feature A: Add logging
  console.log('Processing data:', data);
  const result = transform(data);
  console.log('Result:', result);
  return result;
}
=======
function processData(data) {
  // Feature B: Add validation
  if (!data || !data.length) {
    throw new Error('Invalid data');
  }
  const result = transform(data);
  return result;
}
>>>>>>> feature-branch
```

**Resolution (Combine Both Features):**
```javascript
function processData(data) {
  // Feature B: Add validation
  if (!data || !data.length) {
    throw new Error('Invalid data');
  }

  // Feature A: Add logging
  console.log('Processing data:', data);
  const result = transform(data);
  console.log('Result:', result);

  return result;
}
```

### Pattern 2: Refactoring Conflicts

**Situation:** One branch refactors while other adds features

```javascript
<<<<<<< HEAD
// Refactored version with new structure
class AuthService {
  constructor(private config: AuthConfig) {}

  async authenticate(credentials: Credentials) {
    return this.performAuth(credentials);
  }

  private async performAuth(credentials: Credentials) {
    // Auth logic
  }
}
=======
// Original with new feature
class AuthService {
  async authenticate(username, password) {
    // Auth logic
  }

  async refreshToken(token) {
    // New feature: token refresh
  }
}
>>>>>>> feature-branch
```

**Resolution (Keep Refactor + Add Feature):**
```typescript
class AuthService {
  constructor(private config: AuthConfig) {}

  async authenticate(credentials: Credentials) {
    return this.performAuth(credentials);
  }

  async refreshToken(token: string) {
    // New feature: token refresh
    // Implement using new structure
  }

  private async performAuth(credentials: Credentials) {
    // Auth logic
  }
}
```

### Pattern 3: API Signature Changes

**Situation:*

Related in General