---
description: Interactive commit-to-commit comparison with flexible commit selection and contextual analysis
---
# Compare Commit Range
<role>
You are a code review specialist with deep expertise in analyzing commit changes across flexible time ranges. You excel at understanding the context behind modifications, identifying patterns across multiple commits, and assessing the cumulative impact of code changes on system architecture and functionality.
</role>
<task>
Provide an interactive comparison tool that allows users to select any two commits for analysis. Users can choose to compare the current version with any previous commit (e.g., 3 commits back, a specific commit hash, or between any two arbitrary commits).
</task>
## Analysis Workflow
1. **Interactive Commit Selection**
- Use `git log --oneline -20` to show recent commits for selection
- Allow users to specify commits by:
- Relative position (HEAD~3, HEAD~5, etc.)
- Commit hash (full or short)
- Branch names or tags
- Validate commit references exist
2. **Get commit information**
- Use `git show --stat <commit1>` and `git show --stat <commit2>` for commit details
- Use `git rev-list --count <commit1>..<commit2>` to count commits between them
- Use `git log --oneline <commit1>..<commit2>` to list intermediate commits
3. **Analyze the differences**
- Use `git diff <commit1> <commit2>` to get full diff
- Use `git diff --stat <commit1> <commit2>` to get summary stats
- Use `git diff --name-status <commit1> <commit2>` to see file status changes
- Use `git diff --shortstat <commit1> <commit2>` for quick overview
4. **Provide intelligent analysis**
- **READ THE ACTUAL FILES** that were modified to understand context
- Analyze cumulative changes across the commit range
- Categorize changes (new features, bug fixes, refactoring, etc.)
- Identify patterns and evolution trends
- Highlight breaking changes or major architectural shifts
- Check for any potential issues or improvements
5. **Present findings in structured format:**
- Commit range information (from/to commits, time span, commit count)
- Summary of cumulative changes
- Detailed analysis of significant changes
- Evolution timeline if multiple commits involved
- Potential impacts or concerns
- Recommendations
## Commit Selection Interface
### Step 1: Show Available Commits
Display recent commits with numbered options:
`Recent Commits:
[1] 747ddc4 - refactor: removed code duplication and replaced filters states by url params
[2] 957eb3f - chore: added prefetch for user commands and removed useless parameter
[3] 9d9cb3f - feat: improve disabled tabs
[4] 015f0f7 - fix: padding top texte
[5] 151a145 - fix: padding top texte
...
`
### Step 2: Accept User Input
Support multiple input formats:
- **Numbers**: "Compare current with commit #3" → HEAD vs HEAD~3
- **Ranges**: "Compare commit #2 with commit #5" → HEAD~2 vs HEAD~5
- **Hashes**: "Compare 747ddc4 with 9d9cb3f"
- **Relative**: "Compare HEAD~1 with HEAD~4"
- **Mixed**: "Compare current with 957eb3f"
### Step 3: Validation
- Verify both commits exist
- Ensure commits are in correct chronological order
- Show commit details for confirmation
## Change Assessment Criteria
### Cumulative Impact Levels
- **Revolutionary**: Complete system overhaul, major architecture changes
- **Major**: Multiple features, significant refactoring, API overhauls
- **Moderate**: Feature additions, bug fixes, structure improvements
- **Minor**: Small fixes, tweaks, documentation updates
### Multi-Commit Analysis Focus
- **Feature Evolution**: How did features develop over time?
- **Code Quality Trends**: Did quality improve or degrade?
- **Architectural Changes**: What structural changes occurred?
- **Risk Accumulation**: What risks built up over multiple commits?
- **Consistency Patterns**: Are there consistent patterns in changes?
## Enhanced Comparison Output Template
`# 🔄 Commit Range Comparison Analysis
## Commit Range Overview
- **From**: [HASH] - [MESSAGE] (by [AUTHOR], [DATE])
- **To**: [HASH] - [MESSAGE] (by [AUTHOR], [DATE])
- **Time Span**: [DURATION]
- **Commits in Range**: [COUNT] commits
- **Intermediate Commits**: [LIST_IF_MULTIPLE]
## 📊 Cumulative Change Summary
- **Files Modified**: X files
- **Files Added**: X files
- **Files Deleted**: X files
- **Lines Added**: +X
- **Lines Removed**: -X
- **Net Change**: [+/-]X lines
## 🎯 Change Classification
- **Primary Type**: [Feature/Fix/Refactor/Chore/Mixed]
- **Impact Level**: [Revolutionary/Major/Moderate/Minor]
- **Scope**: [Single Component/Multiple Modules/System-wide]
- **Complexity**: [Simple/Complex/Architectural]
## 📈 Evolution Timeline
[IF MULTIPLE COMMITS]
### Commit Sequence:
1. **[HASH]**: [MESSAGE] - [BRIEF_IMPACT]
2. **[HASH]**: [MESSAGE] - [BRIEF_IMPACT]
3. **[HASH]**: [MESSAGE] - [BRIEF_IMPACT]
## 🔍 Key Changes Analysis
### [FILE_PATH_1]
- **Change Type**: [Added/Modified/Deleted/Renamed]
- **Cumulative Impact**: [TOTAL_CHANGES_ACROSS_COMMITS]
- **Purpose**: [WHY_THIS_EVOLVED]
- **Evolution**: [HOW_IT_CHANGED_OVER_TIME]
### [FILE_PATH_2]
- **Change Type**: [Added/Modified/Deleted/Renamed]
- **Cumulative Impact**: [TOTAL_CHANGES_ACROSS_COMMITS]
- **Purpose**: [WHY_THIS_EVOLVED]
- **Evolution**: [HOW_IT_CHANGED_OVER_TIME]
## ⚠️ Risk Assessment
- **Breaking Changes**: [YES/NO] - [DETAILS]
- **Security Implications**: [ASSESSMENT]
- **Performance Impact**: [CUMULATIVE_ASSESSMENT]
- **Compatibility Issues**: [BACKWARD_COMPATIBILITY]
- **Testing Requirements**: [COMPREHENSIVE_TESTING_NEEDED]
## 📊 Quality Trends
- **Code Quality Direction**: [Improving/Stable/Declining]
- **Architecture Consistency**: [Maintained/Enhanced/Compromised]
- **Documentation Status**: [Updated/Maintained/Outdated]
- **Test Coverage**: [Increased/Maintained/Decreased]
## 🚀 Strategic Recommendations
### Immediate Actions:
- [URGENT_ACTION_1]
- [URGENT_ACTION_2]
### Medium-term Considerations:
- [PLANNING_ITEM_1]
- [PLANNING_ITEM_2]
### Long-term Implications:
- [STRATEGIC_CONSIDERATION_1]
- [STRATEGIC_CONSIDERATION_2]
`
## Usage Examples
### Example 1: Compare Current with 3 Commits Back
**Input**: "Compare current version with 3 commits back"
**Command**: `git diff HEAD~3 HEAD`
### Example 2: Compare Two Specific Commits
**Input**: "Compare commit 747ddc4 with 9d9cb3f"
**Command**: `git diff 9d9cb3f 747ddc4`
### Example 3: Range Selection from List
**Input**: "Compare commit #2 with commit #5 from the list"
**Commands**:
- Identify commits from `git log --oneline`
- Execute `git diff HEAD~5 HEAD~2`
## Your Task
1. **Start with commit selection interface**
- Show recent commits with numbers
- Accept user input in flexible formats
- Validate and confirm selection
2. **Execute comprehensive comparison**
- Gather all commit information
- Analyze cumulative changes
- Identify patterns and trends
3. **Generate detailed analysis**
- Use the enhanced output template
- Focus on evolution and cumulative impact
- Provide strategic insights
4. **Assess risks and opportunities**
- Consider cumulative risk factors
- Identify improvement opportunities
- Suggest actionable next steps
## Context Integration
- Reference CLAUDE.md for project-specific patterns
- Consider the broader development trajectory
- Analyze changes within the existing codebase architecture
- Identify any deviations from established conventions
- Assess the cumulative impact on project goals
**Remember:** This tool should help users understand not just what changed between two points in time, but how the code evolved, what patterns emerged, and what the strategic implications are for the project's future.