mcpField
D
diff-preview

diff-preview

github.com/johnlindquist開発2670 回インストール45 週間前に更新
リポジトリ

diff-preview について

diff-previewは、Gitの変更確認やレビュー準備を行う開発者向けスキルです。Gitの比較方法とGeminiへのプロンプトを組み合わせ、変更説明、影響分析、ステージ済みコードのレビュー、コミットメッセージ案の作成を支援します。

主な機能

  1. 01作業ツリー、ステージ、コミット、ブランチの差分比較
  2. 02差分表示の調整と空白の無視
  3. 03Geminiによる変更の説明
  4. 04影響分析とステージ済みコードのレビュー
  5. 05Conventional Commit形式のメッセージ案

活用シーン

  1. 01コミット前のステージ済み変更の確認
  2. 02プルリクエスト用のブランチ差分準備
  3. 03コミット間の変更調査
  4. 04差分に基づくコミットメッセージの作成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/johnlindquist/claude --skill diff-preview

インストール後、Claude Code で/diff-previewを入力して読み込まれたか確認します。

詳細

差分プレビューと分析

AI の支援を受けて git の変更をプレビュー、説明、分析します。

前提条件

# Git
git --version

# Gemini for AI explanations
pip install google-generativeai
export GEMINI_API_KEY=your_api_key

CLI リファレンス

基本的な差分コマンド
# Working directory changes
git diff

# Staged changes
git diff --staged
git diff --cached

# Specific file
git diff path/to/file.ts

# Between commits
git diff abc123 def456

# Between branches
git diff main feature-branch
git diff main...feature-branch  # Since branch diverged

# Show stat summary
git diff --stat
git diff --shortstat

# Name only
git diff --name-only
git diff --name-status  # With status (M/A/D)
差分出力オプション
# Word diff (better for prose)
git diff --word-diff

# Color words
git diff --color-words

# Ignore whitespace
git diff -w
git diff --ignore-all-space

# Context lines
git diff -U10  # 10 lines of context (default 3)

# Show function names
git diff --function-context
コミットの比較
# Last commit
git diff HEAD~1

# Last N commits
git diff HEAD~5

# Specific commit range
git diff abc123..def456

# What changed in a specific commit
git show abc123

AI による分析

変更を説明する
# Get diff and explain
DIFF=$(git diff --staged)
gemini -m pro -o text -e "" "Explain these code changes in plain English:

$DIFF

Summarize:
1. What was changed
2. Why it might have been changed
3. Any potential issues"
影響分析
DIFF=$(git diff main...feature-branch)
gemini -m pro -o text -e "" "Analyze the impact of these changes:

$DIFF

Consider:
1. Breaking changes
2. Performance implications
3. Security considerations
4. Files/systems affected
5. Testing recommendations"
コミット前レビュー
# Review staged changes before commit
git diff --staged | gemini -m pro -o text -e "" "Review this code diff for:
1. Bugs or issues
2. Code style problems
3. Missing error handling
4. Security concerns

Provide specific line references if issues found."
コミットメッセージを生成する
DIFF=$(git diff --staged)
gemini -m pro -o text -e "" "Based on this diff, suggest a commit message:

$DIFF

Use conventional commit format (feat/fix/chore/etc).
First line under 50 chars, then details."

比較パターン

ブランチを比較する
# Summary
git diff main feature-branch --stat

# Full diff
git diff main feature-branch

# Since branch point
git diff main...feature-branch

# Commits unique to feature branch
git log main..feature-branch --oneline
変更点を見つける
# What files changed between commits
git diff --name-only abc123 def456

# What changed in a file
git log -p -- path/to/file.ts

# When was a line added
git blame path/to/file.ts
マージプレビュー
# Preview merge conflicts
git merge --no-commit --no-ff feature-branch
git diff --staged
git merge --abort  # Clean up

ワークフローパターン

コミット前チェック
#!/bin/bash
# Check staged changes before commit

echo "=== Changes to commit ==="
git diff --staged --stat

echo ""
echo "=== Detailed diff ==="
git diff --staged

echo ""
read -p "Proceed with commit? (y/n) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
  git commit
fi
PR レビューの準備
# Get full PR diff for review
BASE=${1:-main}
BRANCH=$(git branch --show-current)

echo "=== Files changed ==="
git diff $BASE...$BRANCH --name-status

echo ""
echo "=== Stats ==="
git diff $BASE...$BRANCH --shortstat

echo ""
echo "=== AI Summary ==="
git diff $BASE...$BRANCH | gemini -m pro -o text -e "" "Summarize this PR's changes for a code reviewer. Focus on the intent and key changes."
特定の変更を追跡する
# Find all changes to a function
git log -p -S "functionName" -- "*.ts"

# Find changes mentioning something
git log -p --grep="JIRA-123"

ベストプラクティス

  1. コミット前にレビューする - 常に git diff --staged を確認します
  2. まず stat を使う - 完全な差分の前に概要を把握します
  3. ベースと比較する - PR のコンテキストには main...branch を使用します
  4. 空白を無視する - 意味のある変更には -w を使用します
  5. AI レビューを依頼する - 複雑な変更の場合に
  6. 重要な差分を保存する - 参照用にファイルへリダイレクトします

コメント