jpskill.com
✍️ ライティング コミュニティ

git-squash-commits

複数のGitコミットを、変更内容に基づいた包括的なコミットメッセージとともに、一つのコミットにまとめることで、煩雑な履歴を整理し、より分かりやすく管理するSkill。

📜 元の英語説明(参考)

Squash multiple git commits into a single commit with an auto-generated comprehensive commit message based on the changes made.

🇯🇵 日本人クリエイター向け解説

一言でいうと

複数のGitコミットを、変更内容に基づいた包括的なコミットメッセージとともに、一つのコミットにまとめることで、煩雑な履歴を整理し、より分かりやすく管理するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o git-squash-commits.zip https://jpskill.com/download/9210.zip && unzip -o git-squash-commits.zip && rm git-squash-commits.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9210.zip -OutFile "$d\git-squash-commits.zip"; Expand-Archive "$d\git-squash-commits.zip" -DestinationPath $d -Force; ri "$d\git-squash-commits.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して git-squash-commits.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → git-squash-commits フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Git Squash Commits Skill

概要

このスキルは、一連の git コミットを、すべての変更を要約した自動生成されたコミットメッセージを持つ単一のコミットに squash するのに役立ちます。コミット履歴とファイルの変更を分析して、包括的で構造化されたコミットメッセージを作成します。

使用場面

  • マージ前の乱雑なコミット履歴の整理
  • 複数の作業途中コミットの統合
  • コードレビューまたはプルリクエストのためのコミットの準備
  • 機能ブランチ履歴の簡略化
  • 不要な中間コミットの削除

前提条件

重要: このスキルを呼び出す前に、squash したい最も古いコミットの親に、手動でブランチをリセットする必要があります。スキルはこれを検証し、必要に応じてプロンプトを表示します。

例:

# abc123 から xyz789 までのコミットを squash したい場合
# まず abc123 の親を見つける
git log --oneline abc123~5..abc123

# 次に親にリセットする (例: parent_commit)
git reset --hard parent_commit

使用方法

このスキルを呼び出す際は、以下を提供してください。

  1. 開始コミット ID: 範囲内で最も古いコミット (squash 後は現在のブランチに含まれません)
  2. 終了コミット ID: 範囲内で最も新しいコミット (squash 後は現在のブランチに含まれません)

スキルは以下を行います。

  1. 現在の HEAD が開始コミットの親にあることを確認する
  2. 開始から終了までのすべてのコミット (両端を含む) を分析する
  3. ファイルの変更とコミットメッセージを調べる
  4. 以下の情報を含む包括的なコミットメッセージを生成する。
    • 概要
    • カテゴリ別にグループ化された主要な変更
    • 詳細な改善と修正
    • 統計 (変更されたファイル数、追加/削除された行数)
  5. 変更を確認するためにビルド/コンパイルを実行するようにユーザーに促す
    • ユーザーの確認を待つ
    • ビルドが失敗した場合は、エラーの解決を支援する
    • ビルドが成功した場合は、次のステップに進む
  6. squash コミットを作成する
  7. 古いコミットがブランチ履歴に存在しないことを確認する
  8. 以下の情報を含むサマリーレコードを ai_docs/git-squash-commits/ ディレクトリに保存する。
    • squash 操作のメタデータ (タイムスタンプ、ブランチ、コミットハッシュ)
    • 生成されたコミットメッセージ
    • 統計と元のコミットのリスト

コミットメッセージの構造

生成されるコミットメッセージは、次の構造に従います。

<Type>: <Brief summary of the main changes>

Major changes:
- <Category 1>: <Description>
- <Category 2>: <Description>
- ...

<Specific area> improvements:
- <Detailed change 1>
- <Detailed change 2>
- ...

Other changes:
- <Miscellaneous improvements>
- ...

This squash consolidates N commits focusing on <focus areas>.

Statistics: X files changed, Y insertions(+), Z deletions(-)

呼び出し例

ユーザーリクエスト:

Help me squash commits from f2da9a6 to d2755e90

スキルの実行フロー:

  1. 現在の HEAD の位置を確認する

  2. 正しい位置にない場合は、ユーザーにプロンプトを表示する:

    Please first reset to the parent of f2da9a6:
    git reset --hard <parent_commit_id>
    
    Then invoke this skill again.
  3. 正しい位置にある場合は、以下に進む:

    • squash されるすべてのコミットをリストする
    • 変更の統計を表示する
    • コミットメッセージとファイルの変更を分析する
    • 包括的なコミットメッセージを生成する
    • ビルド/コンパイルを実行するようにユーザーに促し、確認を待つ
    • ビルドが失敗した場合は、エラーの解決を支援する
    • ビルドが成功した場合は、次のステップに進む
    • git merge --squash d2755e90 を実行する
    • 生成されたメッセージでコミットする
    • 古いコミットがブランチから削除されたことを確認する

実装ガイドライン

ステップ 1: 前提条件の確認

# 現在の HEAD を取得する
git rev-parse HEAD

# 開始コミットの親を取得する
git rev-parse <start_commit>^

# 比較 - 一致する必要がある

ステップ 2: コミットの分析

# squash するコミットをリストする (開始から終了まで、両端を含む)
git log --oneline <start_commit>..<end_commit>

# 終了コミット自体を含める
git log --oneline <end_commit> -1

# 分析のためにコミットメッセージを取得する
git log --format="%s" <start_commit>~1..<end_commit>

ステップ 3: 変更の分析

# ファイルの統計情報を取得する
git diff --stat <start_commit>~1..<end_commit>

# 主要なファイルの詳細な変更を取得する
git diff <start_commit>~1..<end_commit> -- <important_files>

ステップ 4: コミットメッセージの生成

コミットと変更を分析して、以下のようなメッセージを作成します。

  • 主な目的を特定する (Refactor、Feature、Fix など)
  • 変更を機能領域ごとにグループ化する
  • 重要な改善点を強調する
  • 定量的なメトリクスを含める

ステップ 5: ビルドの検証

コミットメッセージを生成した後、squash を実行する前に、変更が正しくビルドされることを確認するようにユーザーに促します。

Please run your project's build/compilation command to verify the changes:
- For Node.js: npm run build or yarn build
- For Python: python -m pytest or your test suite
- For Go: go build ./...
- For Rust: cargo build
- For Java/Maven: mvn compile
- For other projects: use your project-specific build command

Please run the build and let me know:
1. If the build succeeds, I will proceed with creating the squash commit
2. If the build fails, share the error output and I will help resolve it

ユーザーの応答を待ちます。

  • ビルドが成功した場合: ステップ 6 に進む
  • ビルドが失敗した場合: エラーを分析し、問題の修正を支援し、ユーザーにリビルドを依頼し、成功するまで繰り返す

ステップ 6: squash の実行

# すべてのコミットを squash マージする
git merge --squash <end_commit>

# 生成されたメッセージでコミットする
git commit -m "$(cat <<'EOF'
<generated_message_here>
EOF
)"

ステップ 7: 結果の検証

# 新しいコミットが作成されたことを確認する
git log --oneline -3

# 古いコミットが現在のブランチに存在しないことを確認する
git log --oneline HEAD~20..HEAD | grep -E "(<start_commit_short>|<end_commit_short>)"
# 空を返すはず

ステップ 8: ai_docs へのサマリーの保存

# ai_docs ディレクトリ構造が存在しない場合は作成する
mkdir -p ai_docs/git-squash-commits

# タイムスタンプとコミットハッシュでサマリーファイル名を生成する
SUMMARY_FILE="ai_docs/git-squash-commits/$(date +%Y%m%d_%H%M%S)_$(git rev-parse --short HEAD).md"

# 以下の情報を含むサマリーを書き込む:
# - squash 操作のメタデータ

(原文はここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Git Squash Commits Skill

Overview

This skill helps you squash a range of git commits into a single commit with an automatically generated commit message that summarizes all the changes. It analyzes the commit history and file changes to create a comprehensive, well-structured commit message.

When to Use

  • Cleaning up messy commit history before merging
  • Consolidating multiple work-in-progress commits
  • Preparing commits for code review or pull request
  • Simplifying feature branch history
  • Removing unnecessary intermediate commits

Prerequisites

IMPORTANT: Before invoking this skill, you MUST manually reset your branch to the parent of the earliest commit you want to squash. The skill will verify this and prompt you if needed.

Example:

# If you want to squash commits from abc123 to xyz789
# First find the parent of abc123
git log --oneline abc123~5..abc123

# Then reset to the parent (e.g., parent_commit)
git reset --hard parent_commit

Usage

When invoking this skill, provide:

  1. Start commit ID: The earliest commit in the range (will NOT be included in current branch after squash)
  2. End commit ID: The latest commit in the range (will NOT be included in current branch after squash)

The skill will:

  1. Verify the current HEAD is at the parent of the start commit
  2. Analyze all commits between start and end (inclusive)
  3. Examine the file changes and commit messages
  4. Generate a comprehensive commit message with:
    • High-level summary
    • Major changes grouped by category
    • Detailed improvements and fixes
    • Statistics (files changed, lines added/removed)
  5. Prompt user to run build/compilation to verify changes
    • Wait for user confirmation
    • If build fails, help resolve errors
    • If build succeeds, proceed to next step
  6. Create the squash commit
  7. Verify the old commits are no longer in the branch history
  8. Save a summary record to ai_docs/git-squash-commits/ directory containing:
    • Squash operation metadata (timestamp, branch, commit hashes)
    • The generated commit message
    • Statistics and list of original commits

Commit Message Structure

The generated commit message follows this structure:

<Type>: <Brief summary of the main changes>

Major changes:
- <Category 1>: <Description>
- <Category 2>: <Description>
- ...

<Specific area> improvements:
- <Detailed change 1>
- <Detailed change 2>
- ...

Other changes:
- <Miscellaneous improvements>
- ...

This squash consolidates N commits focusing on <focus areas>.

Statistics: X files changed, Y insertions(+), Z deletions(-)

Example Invocation

User request:

Help me squash commits from f2da9a6 to d2755e90

Skill execution flow:

  1. Check current HEAD position

  2. If not at correct position, prompt user:

    Please first reset to the parent of f2da9a6:
    git reset --hard <parent_commit_id>
    
    Then invoke this skill again.
  3. If at correct position, proceed with:

    • List all commits to be squashed
    • Show statistics of changes
    • Analyze commit messages and file changes
    • Generate comprehensive commit message
    • Prompt user to run build/compile and wait for confirmation
    • If build fails, help resolve errors
    • If build succeeds, continue to next step
    • Execute git merge --squash d2755e90
    • Commit with generated message
    • Verify old commits are removed from branch

Implementation Guidelines

Step 1: Verify Prerequisites

# Get current HEAD
git rev-parse HEAD

# Get parent of start commit
git rev-parse <start_commit>^

# Compare - they should match

Step 2: Analyze Commits

# List commits to squash (from start to end, inclusive)
git log --oneline <start_commit>..<end_commit>

# Include the end commit itself
git log --oneline <end_commit> -1

# Get commit messages for analysis
git log --format="%s" <start_commit>~1..<end_commit>

Step 3: Analyze Changes

# Get file statistics
git diff --stat <start_commit>~1..<end_commit>

# Get detailed changes for major files
git diff <start_commit>~1..<end_commit> -- <important_files>

Step 4: Generate Commit Message

Analyze the commits and changes to create a message that:

  • Identifies the main purpose (Refactor, Feature, Fix, etc.)
  • Groups changes by functional area
  • Highlights important improvements
  • Includes quantitative metrics

Step 5: Build Verification

After generating the commit message but before executing the squash, prompt the user to verify the changes build correctly:

Please run your project's build/compilation command to verify the changes:
- For Node.js: npm run build or yarn build
- For Python: python -m pytest or your test suite
- For Go: go build ./...
- For Rust: cargo build
- For Java/Maven: mvn compile
- For other projects: use your project-specific build command

Please run the build and let me know:
1. If the build succeeds, I will proceed with creating the squash commit
2. If the build fails, share the error output and I will help resolve it

Wait for user response:

  • If build succeeds: proceed to Step 6
  • If build fails: analyze the error, help fix issues, ask user to rebuild, repeat until success

Step 6: Execute Squash

# Squash merge all commits
git merge --squash <end_commit>

# Commit with generated message
git commit -m "$(cat <<'EOF'
<generated_message_here>
EOF
)"

Step 7: Verify Result

# Check new commit is created
git log --oneline -3

# Verify old commits are NOT in current branch
git log --oneline HEAD~20..HEAD | grep -E "(<start_commit_short>|<end_commit_short>)"
# Should return empty

Step 8: Save Summary to ai_docs

# Create ai_docs directory structure if not exists
mkdir -p ai_docs/git-squash-commits

# Generate summary filename with timestamp and commit hash
SUMMARY_FILE="ai_docs/git-squash-commits/$(date +%Y%m%d_%H%M%S)_$(git rev-parse --short HEAD).md"

# Write summary containing:
# - Squash operation metadata (date, commit range, new commit hash)
# - Generated commit message
# - Statistics (files changed, insertions, deletions)
# - List of original commits that were squashed
cat > "$SUMMARY_FILE" <<EOF
# Git Squash Summary

**Date**: $(date +"%Y-%m-%d %H:%M:%S")
**Branch**: $(git branch --show-current)
**New Commit**: $(git rev-parse HEAD)

## Commit Range Squashed
- Start: <start_commit>
- End: <end_commit>

## Generated Commit Message
\`\`\`
<paste the generated commit message here>
\`\`\`

## Statistics
<paste git diff --stat output>

## Original Commits
<paste git log --oneline output of squashed commits>
EOF

echo "Summary saved to: $SUMMARY_FILE"

Notes

  • The skill assumes a linear commit history between start and end commits
  • Merge commits in the range will be included in the squash
  • The generated commit message aims to be comprehensive yet concise
  • All original commits will be removed from the current branch history
  • The squash commit will have the current branch HEAD parent as its parent
  • Statistics include all accumulated changes from start to end
  • Summary records: Each squash operation creates a markdown file in ai_docs/git-squash-commits/ directory
    • Filename format: YYYYMMDD_HHMMSS_<short_hash>.md (timestamp + new commit hash)
    • Content includes: operation metadata, generated commit message, statistics, and list of squashed commits
    • Records are useful for auditing and understanding the history of squash operations
    • The ai_docs/ directory should be added to .gitignore if you prefer not to commit these records

Error Handling

If the user hasn't reset to the correct parent commit:

  1. Calculate the correct parent: git rev-parse <start_commit>^
  2. Show current HEAD: git rev-parse HEAD
  3. Instruct user to run: git reset --hard <correct_parent>
  4. Exit and ask user to re-invoke after reset

Best Practices

  • Always verify the commit range before squashing
  • Keep the generated message focused on "what" and "why"
  • Group related changes together
  • Highlight breaking changes or important modifications
  • Include statistics for transparency
  • Always run build/compilation before creating the squash commit to catch errors early
  • Resolve all build errors before proceeding with the squash
  • Test the changes after squashing to ensure nothing broke