Token导航 LogoToken导航TokenDH.com
git-commit-aider MCP Server logo
开发工具stdio官方级别未说明来源级核验

git-commit-aider MCP Server

MCP Server

A simple MCP server that makes git commits on behave of AI, so that you can track AI contribution in your codebase

工具数

1

提示词数

0

GitHub Stars

7

资源数

0
JavaScript开发工具命令行工具

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

MrOrz

提供方

MrOrz

最后核验

2026/5/18 02:19

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

git提交助手MCP服务器

代表AI进行git提交,这样你就可以在代码库中跟踪AI的贡献。

这是一个基于TypeScript的MCP服务器,它提供了一个在Git存储库中提交分阶段更改的工具,同时在提交者的名称后附加“(aider)”。

特性

此MCP服务器只提供一个工具:

commit_staged -提交带有特定消息的分阶段更改。

  • message (string,必填)作为提交消息。
  • cwd (string,可选)指定git命令的工作目录。
  • 自动在提交者名称后附加“(aider)”。
  • 从环境变量中读取提交者姓名和电子邮件(GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL)如果设置,否则回退到 git config user.namegit config user.email.

在代码编辑器中安装此工具后,您可以通过以下方式提示AI:

为我提交更改

这通常发生在人工智能对你的代码库进行了一些更改之后,所以人工智能通常能够从上下文中提供良好的提交消息。

安装

要使用此服务器,请将其配置添加到MCP设置文件中。

{
  "mcpServers": {
    "git-commit-aider": {
      "command": "npx",
      "args": ["mcp-git-commit-aider"]
    }
  }
}

提交者信息从以下位置检索:

  1. 环境变量 GIT_COMMITTER_NAMEGIT_COMMITTER_EMAIL,如下 git惯例.
  2. 输出 git config user.namegit config user.email 命令。

替代:提交后修改作者

如果您不想使用此MCP服务器,也可以使用 git 直接在终端中命令。

您可以先进行正常的提交,然后使用以下git命令更改最后一次提交的作者:

git commit --amend --author="$(git config user.name) (aider) "

这将把最后一次提交的作者更改为您的名字,并附加“(aider)”。

为了简化这个过程,你可以设置一个Git别名。在终端中运行以下命令:

git config --global alias.aimend '!git commit --amend --author="$(git config user.name) (aider) "'

设置后,您可以通过运行以下命令来使用别名:

git aimend

计算AI贡献

带有“(aider)”的承诺可以通过以下方式提取 aider --stats 命令,它将显示AI在代码库中的贡献。

或者,您可以使用以下脚本计算AI在代码库中的贡献,以代码行(添加、删除和总更改)为单位进行衡量。

#!/bin/bash

# Script to calculate line changes (added, deleted, total) by AI and human authors
# between two commits.
# Output is in JSON format.
#
# This logic is extracted and altered from git-quick-stats.sh, MIT license.

# --- Configuration ---
# You may change the config to match your repository's convention.

# String to identify AI-generated commits in author names
AI_MATCHER="(aider)"

# Define patterns for files/paths to be excluded from the calculation.
# These will be converted to git pathspecs like ":(exclude)*package-lock.json"
IGNORE_PATTERNS=(
  "*package-lock.json"
  "*.lock"
)

# --- Helper Functions ---
function print_usage() {
  echo "Usage: $0 "
  echo "  : The revision range to analyze (e.g., HEAD~5..HEAD, my-branch, commit_sha)."
  echo "  Refer to 'git help log' or 'git help revisions' for more range options."
  echo "Example: $0 HEAD~5..HEAD"
  echo "Example: $0 origin..HEAD"
  echo "Example: $0 my-feature-branch"
  echo "Example: $0 abcdef1..fedcba2"
}

# --- Argument Parsing ---
if [ "$#" -ne 1 ]; then
  echo "Error: Incorrect number of arguments. Please provide a single revision range."
  print_usage
  exit 1
fi

REVISION_RANGE="$1"

# --- Main Logic ---

# Construct pathspec arguments for git log
pathspec_args=()
for pattern in "${IGNORE_PATTERNS[@]}"; do
  pathspec_args+=(":(exclude)$pattern")
done

git_log_output=$(git log "$REVISION_RANGE" --numstat --pretty="format:AuthorName:%an" -- "${pathspec_args[@]}")

# DEBUG: Uncomment to check the calculation for each commit.
# echo "$git_log_output"

# Process the log output with awk
result_json=$(echo "$git_log_output" | awk -v ai_matcher="$AI_MATCHER" '
BEGIN {
  ai_added = 0
  ai_deleted = 0
  human_added = 0
  human_deleted = 0
  current_author = ""
  is_ai_author = 0
}

/^AuthorName:/ {
  # Extract author name
  current_author = substr($0, length("AuthorName:") + 1)
  if (index(current_author, ai_matcher) > 0) {
    is_ai_author = 1
  } else {
    is_ai_author = 0
  }
  next
}

# Skip empty lines between commit blocks or lines that are not numstat
NF == 0 || !($1 ~ /^[0-9]+$/ && $2 ~ /^[0-9]+$/) {
  next
}

# Process numstat line:   
{
  added_lines = $1
  deleted_lines = $2

  # Skip binary files where numstat shows "-" for lines
  if (added_lines == "-" || deleted_lines == "-") {
    next
  }

  # Aggregate stats per author and file for details array
  file_name = $3
  # Robust key using File Separator character \034
  key = current_author "\034" file_name

  file_author_added[key] += added_lines
  file_author_deleted[key] += deleted_lines

  if (is_ai_author) {
    ai_added += added_lines
    ai_deleted += deleted_lines
  } else {
    human_added += added_lines
    human_deleted += deleted_lines
  }
}

END {
  ai_total_changed = ai_added + ai_deleted
  human_total_changed = human_added + human_deleted
  overall_total_changed = ai_total_changed + human_total_changed
  ai_percentage = 0.00

  if (overall_total_changed > 0) {
    ai_percentage = (ai_total_changed / overall_total_changed) * 100
  }

  printf "{\n"
  printf "  \"ai_percentage\": %.2f,\n", ai_percentage
  printf "  \"ai_changes\": {\"added\": %d, \"deleted\": %d, \"total\": %d},\n", ai_added, ai_deleted, ai_total_changed
  printf "  \"human_changes\": {\"added\": %d, \"deleted\": %d, \"total\": %d},\n", human_added, human_deleted, human_total_changed

  # Details array
  printf "  \"details\": [\n"
  first_detail = 1
  # Iterate over one of the arrays, keys should be consistent
  for (key in file_author_added) {
    if (!first_detail) {
      printf ",\n"
    }
    first_detail = 0

    # Split key "author\034fileName" into key_parts array
    # key_parts[1] will be author, key_parts[2] will be fileName
    split(key, key_parts, "\034")
    author = key_parts[1]
    fileName = key_parts[2]

    # Escape double quotes for JSON compatibility
    gsub(/"/, "\\\"", author)
    gsub(/"/, "\\\"", fileName)

    detail_added = file_author_added[key] + 0 # Ensure numeric
    detail_deleted = file_author_deleted[key] + 0 # Ensure numeric
    detail_total = detail_added + detail_deleted

    printf "    {\n"
    printf "      \"fileName\": \"%s\",\n", fileName
    printf "      \"author\": \"%s\", \"isAI\": %s,\n", author, (index(author, ai_matcher) > 0 ? "true" : "false")
    printf "      \"added\": %d, \"deleted\": %d, \"total\": %d\n", detail_added, detail_deleted, detail_total
    printf "    }"
  }
  printf "\n  ]\n"
  printf "}\n"
}
')

# --- Output ---
echo "$result_json"

使用示例:

# Assume the script is saved as `calculate_ai_contribution.sh` and is executable (chmod +x calculate_ai_contribution.sh)

# Example 1: Analyze the last 5 commits
./calculate_ai_contribution.sh HEAD~5..HEAD

# Example 2: Analyze commits between a specific commit and HEAD
./calculate_ai_contribution.sh 90a5fcd4..HEAD

# Example 3: Analyze all commits on a feature branch not yet in main
./calculate_ai_contribution.sh main..my-feature-branch

# Example 4: Analyze commits between two tags
./calculate_ai_contribution.sh v1.0..v1.1

# Example output (will vary based on your repository and range):
# {
#   "ai_percentage": 48.53,
#   "ai_changes": { "added": 100, "deleted": 32, "total": 132 },
#   "human_changes": { "added": 103, "deleted": 37, "total": 140 },
#   "details": [
#     {
#       "fileName": "src/featureA.js",
#       "author": "Developer One (aider)", "isAI": true,
#       "added": 60, "deleted": 10, "total": 70
#     },
#     {
#       "fileName": "src/featureB.js",
#       "author": "Developer One (aider)", "isAI": true,
#       "added": 40, "deleted": 22, "total": 62
#     },
#     {
#       "fileName": "src/utils.js",
#       "author": "Developer Two", "isAI": false,
#       "added": 80, "deleted": 15, "total": 95
#     },
#     {
#       "fileName": "README.md",
#       "author": "Developer Two", "isAI": false,
#       "added": 23, "deleted": 22, "total": 45
#     }
#   ]
# }

输出字段说明

JSON输出包含以下字段:

  • ai_percentage:(数字)人工智能作者(按 AI_MATCHER).
  • ai_changes:(Object)一个详细描述聚合线条变化(线条)的对象 added, deleted,以及他们 total)由AI作者制作。
  • human_changes:(Object)一个详细描述聚合线条变化(线条)的对象 added, deleted,以及他们 total)由人类作家创作。
  • details:(对象数组)提供更改的详细细分。数组中的每个对象都表示特定对象的贡献 author 对于一个特定的 fileName,包括线路 added, deleted,以及 total 该作者对该文件所做的更改。

目录标签

目录标签

JavaScript开发工具命令行工具developer-toolsgit-commit-aidermcp-serverai-contributionGit工具本地部署AI协作代码版本控制开发辅助

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP