Back to Skills

retrieve-diff-from-commit

verified

Retrieve code diff from a local git commit. Use this as the first step in a code review pipeline when reviewing local commits.

View on GitHub

Marketplace

codereview-skills

xinbenlv/codereview-skills

Plugin

codereview

Repository

xinbenlv/codereview-skills

skills/retrieve-diff-from-commit/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/xinbenlv/codereview-skills/blob/main/skills/retrieve-diff-from-commit/SKILL.md -a claude-code --skill retrieve-diff-from-commit

Installation paths:

Claude
.claude/skills/retrieve-diff-from-commit/
Powered by add-skill CLI

Instructions

# Retrieve Diff from Commit Skill

An **input skill** that retrieves code diff from local git commits. This is the entry point for reviewing local changes before they are pushed.

## Role

- **Extract**: Get the diff content from a specific commit or range of commits
- **Format**: Prepare the diff in a format suitable for code review
- **Context**: Gather commit metadata (author, message, timestamp)

## Inputs

| Input | Required | Description |
|-------|----------|-------------|
| `commit_sha` | Optional | Specific commit SHA to review (defaults to HEAD) |
| `commit_range` | Optional | Range of commits (e.g., `main..HEAD`, `HEAD~3..HEAD`) |
| `base_branch` | Optional | Compare current branch against base (e.g., `main`, `develop`) |

## Outputs

| Output | Description |
|--------|-------------|
| `diff` | The unified diff content |
| `files_changed` | List of files modified with change type (added/modified/deleted) |
| `commit_info` | Commit metadata (SHA, author, message, timestamp) |
| `stats` | Summary statistics (lines added, deleted, files changed) |

## Usage

### Review Single Commit

```bash
# Get diff for specific commit
git show <commit_sha> --format="%H%n%an%n%ae%n%s%n%b" --stat

# Get unified diff
git diff <commit_sha>^..<commit_sha>
```

### Review Commit Range

```bash
# Get diff for range
git diff <base_commit>..<head_commit>

# Get list of commits in range
git log --oneline <base_commit>..<head_commit>
```

### Review Branch Against Base

```bash
# Compare feature branch to main
git diff main...HEAD

# Get merge-base
git merge-base main HEAD
```

## Step 1: Identify the Scope

Determine what to review:

| Scenario | Command | Use Case |
|----------|---------|----------|
| **Last commit** | `git diff HEAD~1..HEAD` | Quick review of latest change |
| **All uncommitted** | `git diff` | Review before committing |
| **Staged changes** | `git diff --cached` | Review what will be committed |
| **Branch diff** | `git diff main...HEAD` | Full feature review |

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
4313 chars