git_commits_details
Retrieve detailed commit information including full messages and diffs from Git repositories, with filtering by branch, date, author, or content.
Instructions
Get detailed information about commits including full messages and diffs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_url | Yes | The URL of the Git repository | |
| branch | No | The branch to get commits from | main |
| max_count | No | Maximum number of commits to retrieve | |
| include_diff | No | Whether to include the commit diffs | |
| since | No | Get commits after this date (e.g., "1 week ago", "2023-01-01") | |
| until | No | Get commits before this date (e.g., "yesterday", "2023-12-31") | |
| author | No | Filter by author (optional) | |
| grep | No | Filter commits by message content (optional) |
Implementation Reference
- Main handler function for git_commits_details tool. Clones repository, fetches detailed commit logs using simpleGit, optionally retrieves diffs and changed files for each commit, applies filters (author, date, grep), and returns formatted JSON response.export async function handleGitCommitsDetails({ repo_url, branch = "main", max_count = 10, include_diff = false, author, since, until, grep, }) { try { const repoPath = await cloneRepo(repo_url); const git = simpleGit(repoPath); // Ensure branch exists locally const branches = await git.branch(); if (!branches.all.includes(branch)) { await git.fetch("origin", branch); } // Prepare log options with full details const logOptions = { maxCount: max_count, "--format": "fuller", // Get more detailed commit info }; if (author) { logOptions["--author"] = author; } if (since) { logOptions["--since"] = since; } if (until) { logOptions["--until"] = until; } if (grep) { logOptions["--grep"] = grep; } // Get commit history with full details const log = await git.log(logOptions, branch); // Enhance with additional details const commitsDetails = []; for (const commit of log.all) { const commitDetails = { hash: commit.hash, author: commit.author_name, author_email: commit.author_email, committer: commit.committer_name, committer_email: commit.committer_email, date: commit.date, message: commit.message, body: commit.body || "", refs: commit.refs, }; // Get the commit diff if requested if (include_diff) { if (commit.parents && commit.parents.length > 0) { // For normal commits with parents const diff = await git.diff([`${commit.hash}^..${commit.hash}`]); commitDetails.diff = diff; } else { // For initial commits with no parents const diff = await git.diff([ "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commit.hash, ]); commitDetails.diff = diff; } // Get list of changed files const showResult = await git.show([ "--name-status", "--oneline", commit.hash, ]); // Parse the changed files from the result const fileLines = showResult .split("\n") .slice(1) // Skip the first line (commit summary) .filter(Boolean); // Remove empty lines commitDetails.changed_files = fileLines .map((line) => { const match = line.match(/^([AMDTRC])\s+(.+)$/); if (match) { return { status: match[1], file: match[2], }; } return null; }) .filter(Boolean); } commitsDetails.push(commitDetails); } return { content: [ { type: "text", text: JSON.stringify( { commits: commitsDetails, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to get commit details: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:283-330 (schema)MCP tool schema definition for 'git_commits_details', including name, description, and detailed inputSchema with parameters, types, defaults, and required fields.{ name: "git_commits_details", description: "Get detailed information about commits including full messages and diffs.", inputSchema: { type: "object", properties: { repo_url: { type: "string", description: "The URL of the Git repository", }, branch: { type: "string", description: "The branch to get commits from", default: "main", }, max_count: { type: "integer", description: "Maximum number of commits to retrieve", default: 10, }, include_diff: { type: "boolean", description: "Whether to include the commit diffs", default: false, }, since: { type: "string", description: 'Get commits after this date (e.g., "1 week ago", "2023-01-01")', }, until: { type: "string", description: 'Get commits before this date (e.g., "yesterday", "2023-12-31")', }, author: { type: "string", description: "Filter by author (optional)", }, grep: { type: "string", description: "Filter commits by message content (optional)", }, }, required: ["repo_url"], }, },
- src/server.js:898-927 (registration)Registration of tool handlers in the handlersMap object, mapping 'git_commits_details' to the handleGitCommitsDetails function for dynamic tool execution.this.handlersMap = { // Primary handlers git_directory_structure: handleGitDirectoryStructure, git_read_files: handleGitReadFiles, git_branch_diff: handleGitBranchDiff, git_commit_history: handleGitCommitHistory, git_commits_details: handleGitCommitsDetails, git_local_changes: handleGitLocalChanges, git_search_code: handleGitSearchCode, git_commit: handleGitCommit, git_track: handleGitTrack, git_checkout_branch: handleGitCheckoutBranch, git_delete_branch: handleGitDeleteBranch, git_merge_branch: handleGitMergeBranch, git_push: handleGitPush, git_pull: handleGitPull, git_stash: handleGitStash, git_create_tag: handleGitCreateTag, git_rebase: handleGitRebase, git_config: handleGitConfig, git_reset: handleGitReset, git_archive: handleGitArchive, git_attributes: handleGitAttributes, git_blame: handleGitBlame, git_clean: handleGitClean, git_hooks: handleGitHooks, git_lfs: handleGitLFS, git_lfs_fetch: handleGitLFSFetch, git_revert: handleGitRevert, };
- src/handlers/index.js:9-13 (registration)Import of handleGitCommitsDetails from commit-operations.js into the handlers index for re-export to server.js.handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack, } from "./commit-operations.js";
- src/handlers/index.js:49-52 (registration)Re-export of handleGitCommitsDetails from handlers/index.js, making it available for import in server.js.handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack,