Skip to main content
Glama

git_commit_history

Retrieve and filter commit history for a specific Git repository branch, with options to limit results by author, date range, or message content.

Instructions

Get commit history for a branch with optional filtering.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
authorNoFilter by author (optional)
branchNoThe branch to get history frommain
grepNoFilter commits by message content (optional)
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

  • Core implementation of the git_commit_history tool handler. Clones the repository, applies filters to git log, formats commit data, and returns structured JSON response.
    export async function handleGitCommitHistory({ repo_url, branch = "main", max_count = 10, author, since, until, grep, }) { try { const repoPath = await cloneRepo(repo_url); const git = simpleGit(repoPath); // Prepare log options const logOptions = { maxCount: max_count, }; if (author) { logOptions["--author"] = author; } if (since) { logOptions["--since"] = since; } if (until) { logOptions["--until"] = until; } if (grep) { logOptions["--grep"] = grep; } // Make sure branch exists locally const branches = await git.branch(); if (!branches.all.includes(branch)) { await git.fetch("origin", branch); } // Get commit history const log = await git.log(logOptions, branch); // Format the commits const commits = log.all.map((commit) => ({ hash: commit.hash, author: commit.author_name, email: commit.author_email, date: commit.date, message: commit.message, body: commit.body || "", })); return { content: [ { type: "text", text: JSON.stringify({ commits }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to get commit history: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
  • Input schema and metadata definition for the git_commit_history tool used in MCP tool listing.
    name: "git_commit_history", description: "Get commit history for a branch with optional filtering.", inputSchema: { type: "object", properties: { repo_url: { type: "string", description: "The URL of the Git repository", }, branch: { type: "string", description: "The branch to get history from", default: "main", }, max_count: { type: "integer", description: "Maximum number of commits to retrieve", default: 10, }, author: { type: "string", description: "Filter by author (optional)", }, 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")', }, grep: { type: "string", description: "Filter commits by message content (optional)", }, }, required: ["repo_url"], }, },
  • src/server.js:903-903 (registration)
    Maps the tool name 'git_commit_history' to its handler function in the server's handlersMap.
    git_commit_history: handleGitCommitHistory,
  • src/server.js:886-886 (registration)
    Registers 'git_log' as an alias for the 'git_commit_history' tool.
    git_log: "git_commit_history",
  • Imports the handleGitCommitHistory function from its implementation file for re-export and use in server.
    handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack, } from "./commit-operations.js";

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