Skip to main content
Glama

git_commits_details

Retrieve detailed commit data from Git repositories, including messages and optional diffs. Filter by branch, date range, author, or message content to streamline code history analysis.

Instructions

Get detailed information about commits including full messages and diffs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
authorNoFilter by author (optional)
branchNoThe branch to get commits frommain
grepNoFilter commits by message content (optional)
include_diffNoWhether to include the commit diffs
max_countNoMaximum number of commits to retrieve
repo_urlYesThe URL of the Git repository
sinceNoGet commits after this date (e.g., "1 week ago", "2023-01-01")
untilNoGet commits before this date (e.g., "yesterday", "2023-12-31")

Implementation Reference

  • The primary handler function that implements the git_commits_details tool. It clones the repository, fetches detailed commit logs using simple-git, optionally retrieves diffs and changed files for each commit, and returns formatted JSON output.
    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, }; } }
  • The tool schema definition including name, description, and detailed inputSchema with properties and defaults matching the handler parameters.
    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:904-904 (registration)
    Registration of the tool name 'git_commits_details' mapped to the handler function 'handleGitCommitsDetails' in the central handlersMap used by the MCP server.
    git_commits_details: handleGitCommitsDetails,
  • Import of the handleGitCommitsDetails handler from its implementation file.
    handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack, } from "./commit-operations.js";
  • Re-export of the handleGitCommitsDetails function for use by server.js.
    handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bsreeram08/git-commands-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server