[GH-ISSUE #309] [Feature Request] Add optional commit message statistics embedding #109

Closed
opened 2026-03-02 04:11:52 +03:00 by kerem · 3 comments
Owner

Originally created by @zaizyp on GitHub (Dec 25, 2025).
Original GitHub issue: https://github.com/git-ai-project/git-ai/issues/309

Feature Request: Optional Commit Message Statistics Embedding

Summary

I would like to propose adding an optional feature to embed AI code statistics directly into commit messages. This would
provide visibility into AI-generated code contributions at the commit level without requiring external tools to view the
statistics.

Use Case

Currently, git-ai stores all AI authorship metadata in Git Notes (refs/notes/ai), which is excellent for preserving
commit integrity. However, some workflows would benefit from having summary statistics visible directly in commit
messages:

  1. Quick visibility: View AI contribution stats without running git-ai stats
  2. GitHub/GitLab UI: Statistics visible in web interface commit views
  3. Code review: Reviewers can quickly see AI/human contribution ratios
  4. Audit trail: Historical record embedded in commit history

Proposed Implementation

Configuration

Add a new configuration option to control this behavior:

# Enable commit message embedding
git config git-ai.commit-message-stats true

# Optional: Customize format
git config git-ai.commit-message-format "[AI: {ai_additions} lines, Human: {human_additions} lines]"

# Default format (if not specified):
# [git-ai: H={human} A={ai} AA={accepted} TAI={total_ai} TAD={total_del}]

Behavior

When enabled, the commit message would be modified to include statistics:

Before:

Add user authentication feature
Implemented login and registration endpoints with JWT tokens.

After:

Add user authentication feature
Implemented login and registration endpoints with JWT tokens.
[git-ai: H=15 A=8 AA=8 TAI=8 TAD=0]

Implementation Location

The modification would happen in:

  • src/commands/checkpoint.rs - During checkpoint creation
  • src/commands/post_commit.rs - Before writing to Git Notes
  • New configuration module for commit message formatting

Questions for Maintainers

  1. Alignment: Does this align with the project's philosophy of keeping commits clean and using Git Notes for metadata?
  2. Implementation approach: Would you prefer:
  • Option A: Modify commit message before commit (in post-commit hook)
  • Option B: Create a separate command like git-ai embed-stats
  • Option C: A new preset flag git-ai checkpoint --embed-stats
  1. Configuration: Should this be:
  • Global config only
  • Per-repository config
  • Command-line flag override
  1. Format: What format would you prefer for the statistics in commit messages?

Alternative Approaches Considered

  1. Git Notes only: Current approach - keeps commits clean
  2. Separate metadata file: Track in repository (bloats history)
  3. GitHub App: External service to annotate commits (complex)

Benefits

  • No breaking changes to existing functionality
  • Optional feature (disabled by default)
  • Backward compatible
  • Works with existing Git workflows
  • Can be toggled per-repository

Concerns

  • Increases commit message size
  • May conflict with commit message conventions
  • Requires careful handling during rebase/merge

Contribution Plan

If this feature is welcomed, I'm prepared to:

  1. Implement the core functionality
  2. Add comprehensive tests
  3. Update documentation
  4. Ensure backward compatibility
  5. Handle edge cases (rebase, merge, etc.)

Environment

  • Use case: Multi-developer teams using AI tools
  • GitLab/GitHub: Both platforms
  • Workflow: Mixed AI + human development

Looking forward to your feedback on this proposal. I'm happy to adjust the implementation approach based on your guidance.
Note: Since I'm not a native English speaker, this content was generated with AI assistance. Please let me know if there are any unclear parts or areas that need improvement.

Originally created by @zaizyp on GitHub (Dec 25, 2025). Original GitHub issue: https://github.com/git-ai-project/git-ai/issues/309 ## Feature Request: Optional Commit Message Statistics Embedding ### Summary I would like to propose adding an optional feature to embed AI code statistics directly into commit messages. This would provide visibility into AI-generated code contributions at the commit level without requiring external tools to view the statistics. ### Use Case Currently, git-ai stores all AI authorship metadata in Git Notes (`refs/notes/ai`), which is excellent for preserving commit integrity. However, some workflows would benefit from having summary statistics visible directly in commit messages: 1. **Quick visibility**: View AI contribution stats without running `git-ai stats` 2. **GitHub/GitLab UI**: Statistics visible in web interface commit views 3. **Code review**: Reviewers can quickly see AI/human contribution ratios 4. **Audit trail**: Historical record embedded in commit history ### Proposed Implementation #### Configuration Add a new configuration option to control this behavior: ```bash # Enable commit message embedding git config git-ai.commit-message-stats true # Optional: Customize format git config git-ai.commit-message-format "[AI: {ai_additions} lines, Human: {human_additions} lines]" # Default format (if not specified): # [git-ai: H={human} A={ai} AA={accepted} TAI={total_ai} TAD={total_del}] ``` Behavior When enabled, the commit message would be modified to include statistics: Before: ``` Add user authentication feature Implemented login and registration endpoints with JWT tokens. ``` After: ``` Add user authentication feature Implemented login and registration endpoints with JWT tokens. [git-ai: H=15 A=8 AA=8 TAI=8 TAD=0] ``` Implementation Location The modification would happen in: - src/commands/checkpoint.rs - During checkpoint creation - src/commands/post_commit.rs - Before writing to Git Notes - New configuration module for commit message formatting Questions for Maintainers 1. Alignment: Does this align with the project's philosophy of keeping commits clean and using Git Notes for metadata? 2. Implementation approach: Would you prefer: - Option A: Modify commit message before commit (in post-commit hook) - Option B: Create a separate command like git-ai embed-stats <commit> - Option C: A new preset flag git-ai checkpoint --embed-stats 3. Configuration: Should this be: - Global config only - Per-repository config - Command-line flag override 4. Format: What format would you prefer for the statistics in commit messages? Alternative Approaches Considered 1. Git Notes only: Current approach - keeps commits clean 2. Separate metadata file: Track in repository (bloats history) 3. GitHub App: External service to annotate commits (complex) Benefits - ✅ No breaking changes to existing functionality - ✅ Optional feature (disabled by default) - ✅ Backward compatible - ✅ Works with existing Git workflows - ✅ Can be toggled per-repository Concerns - ❌ Increases commit message size - ❌ May conflict with commit message conventions - ❌ Requires careful handling during rebase/merge Contribution Plan If this feature is welcomed, I'm prepared to: 1. Implement the core functionality 2. Add comprehensive tests 3. Update documentation 4. Ensure backward compatibility 5. Handle edge cases (rebase, merge, etc.) Environment - Use case: Multi-developer teams using AI tools - GitLab/GitHub: Both platforms - Workflow: Mixed AI + human development --- Looking forward to your feedback on this proposal. I'm happy to adjust the implementation approach based on your guidance. Note: Since I'm not a native English speaker, this content was generated with AI assistance. Please let me know if there are any unclear parts or areas that need improvement.
kerem closed this issue 2026-03-02 04:11:53 +03:00
Author
Owner

@acunniffe commented on GitHub (Dec 28, 2025):

Hey @zaizyp thanks for the great write-up!

I think this depends on the goal a lot. If you want commit stats, this can work. If you want PR stats (ie this patch it's XX% AI), that's a little more complicated.

When you commit code git will give you the line summary stats for the commit +121 -15. If there are 5 commits in a PR, you might think you can just sum the line level stats for all commits, but frequently the result of that sum is different than the # you'd get if you git diff main..branch --stat.

Git AI is the same. AI Stats for any commit might differ from the stats you get for a range of commits. That's why we have a git-ai stats <sha>..<sha> command for "range" authorship.

Would the GH Action work for you?
https://usegitai.com/docs/metrics/github-actions

Two options that I think make sense

  • Maybe the best way is to amend commit stats to merge commit messages? It wouldn't be on every commit, but it would show up when they merge, and be in the context of the default branch.
  • You could update the GH Action code to comment on the PR and update its comment as more commits come in
<!-- gh-comment-id:3694733692 --> @acunniffe commented on GitHub (Dec 28, 2025): Hey @zaizyp thanks for the great write-up! I think this depends on the goal a lot. If you want commit stats, this can work. If you want PR stats (ie this patch it's XX% AI), that's a little more complicated. When you commit code git will give you the line summary stats for the commit `+121 -15`. If there are 5 commits in a PR, you might think you can just sum the line level stats for all commits, but frequently the result of that sum is different than the # you'd get if you `git diff main..branch --stat`. Git AI is the same. AI Stats for any commit might differ from the stats you get for a range of commits. That's why we have a `git-ai stats <sha>..<sha>` command for "range" authorship. Would the GH Action work for you? https://usegitai.com/docs/metrics/github-actions Two options that I think make sense - Maybe the best way is to amend commit stats to merge commit messages? It wouldn't be on every commit, but it would show up when they merge, and be in the context of the default branch. - You could update the GH Action code to comment on the PR and update its comment as more commits come in
Author
Owner

@zaizyp commented on GitHub (Dec 28, 2025):

Hi @acunniffe , thanks for the thoughtful feedback!

I actually went ahead and implemented this feature in PR #[310] 😊

What I Built

A configurable, opt-in feature that adds AI stats to commit messages automatically:

Add user authentication

Stats: ██████████░░░░░░░░░░ | 52% you, 0% mixed, 48% ai
AI: 435 accepted, 618 generated, waited 4m 13s

Why This Complements git-ai

You're absolutely right about the commit vs PR stats difference. Here's why this feature is valuable alongside your existing tools:

1. Local Development Workflow

  • When I'm working on a feature branch with multiple commits, I want immediate visibility into each commit's AI contribution
  • git-ai stats <sha> requires me to remember the SHA and run a separate command
  • With this, the stats are right there in the commit message

2. Platform Agnostic

  • Doesn't depend on GitHub or GitLab specific features
  • Works with any git hosting (Bitbucket, Gitea, self-hosted)
  • Pure git native, no platform lock-in

3. Code Review Context

  • Reviewers can see AI stats inline without checking out the branch
  • No need to run git-ai stats <sha>..<sha> for every commit in a PR
  • Stats are preserved in the git history forever

4. Git Log Readability

git log --oneline --graph
# Shows: feat: add auth (60% AI)

Implementation Quality

Opt-in by default - No behavior change unless enabled
Configurable - Two-layer configuration for flexibility:

# 1. Enable the feature (required)
git-ai config set --add feature_flags.commit_message_stats true

# 2. Customize format (optional)
git config ai.commit-message-stats.format text          # or markdown
git config ai.commit-message-stats.include-progress-bar true
git config ai.commit-message-stats.bar-width 20
git config ai.commit-message-stats.template "{original_message}\n\n{stats}"

Handles edge cases:

  • Empty commits (no stats shown)
  • Feature flag disables the feature entirely
  • Works with --amend and rebase operations
  • Preserves original commit message if stats generation fails

Clean architecture:

  • New commit_message.rs module for formatting
  • Integrates with existing post_commit hook infrastructure
  • Uses existing stats_command for consistency

Addresses Your Concerns

"Stats for any commit might differ from stats for a range"

This feature doesn't change that. It simply displays commit-level stats in the message. For PR-level stats, users still use:

  • git-ai stats <sha>..<sha>
  • The GitHub Action

Why Not Just Use the GitHub Action?

The GitHub Action is great for merged PRs, but:

  1. It doesn't help during active development
  2. It requires pushing and waiting for CI
  3. It doesn't show stats for abandoned branches
  4. It's not visible in local git log
  5. Requires specific platform (GitHub/GitLab)

My Ask:

Merge as experimental feature

  • Behind feature flag
  • Document as "local development aid"
  • Gather user feedback

Testing

The PR includes:

  • Unit tests for message formatting
  • Integration tests for the full flow
  • Edge case coverage (empty commits, feature disabled, etc.)
  • Snapshot tests for output format

My Questions

  1. Is the two-layer config approach acceptable? (feature flag + git config)
  2. Should stats be appended or prepended to the commit message?
  3. Any concerns about the implementation approach?

I'm happy to iterate on this based on your guidance. The core value I'm trying to add is better local visibility into AI contributions without disrupting existing workflows.

Thanks again for building git-ai and considering this enhancement!

<!-- gh-comment-id:3694872979 --> @zaizyp commented on GitHub (Dec 28, 2025): Hi @acunniffe , thanks for the thoughtful feedback! I actually went ahead and implemented this feature in PR #[310] 😊 ## What I Built A **configurable, opt-in** feature that adds AI stats to commit messages automatically: ``` Add user authentication Stats: ██████████░░░░░░░░░░ | 52% you, 0% mixed, 48% ai AI: 435 accepted, 618 generated, waited 4m 13s ``` ## Why This Complements git-ai You're absolutely right about the commit vs PR stats difference. Here's why this feature is valuable **alongside** your existing tools: ### 1. **Local Development Workflow** - When I'm working on a feature branch with multiple commits, I want **immediate visibility** into each commit's AI contribution - `git-ai stats <sha>` requires me to remember the SHA and run a separate command - With this, the stats are **right there** in the commit message ### 2. **Platform Agnostic** - Doesn't depend on GitHub or GitLab specific features - Works with any git hosting (Bitbucket, Gitea, self-hosted) - Pure git native, no platform lock-in ### 3. **Code Review Context** - Reviewers can see AI stats **inline** without checking out the branch - No need to run `git-ai stats <sha>..<sha>` for every commit in a PR - Stats are preserved in the git history forever ### 4. **Git Log Readability** ```bash git log --oneline --graph # Shows: feat: add auth (60% AI) ``` ## Implementation Quality ✅ **Opt-in by default** - No behavior change unless enabled ✅ **Configurable** - Two-layer configuration for flexibility: ```bash # 1. Enable the feature (required) git-ai config set --add feature_flags.commit_message_stats true # 2. Customize format (optional) git config ai.commit-message-stats.format text # or markdown git config ai.commit-message-stats.include-progress-bar true git config ai.commit-message-stats.bar-width 20 git config ai.commit-message-stats.template "{original_message}\n\n{stats}" ``` ✅ **Handles edge cases**: - Empty commits (no stats shown) - Feature flag disables the feature entirely - Works with `--amend` and rebase operations - Preserves original commit message if stats generation fails ✅ **Clean architecture**: - New `commit_message.rs` module for formatting - Integrates with existing `post_commit` hook infrastructure - Uses existing `stats_command` for consistency ## Addresses Your Concerns > "Stats for any commit might differ from stats for a range" **This feature doesn't change that.** It simply displays commit-level stats in the message. For PR-level stats, users still use: - `git-ai stats <sha>..<sha>` - The GitHub Action ## Why Not Just Use the GitHub Action? The GitHub Action is great for **merged PRs**, but: 1. It doesn't help during **active development** 2. It requires **pushing and waiting** for CI 3. It doesn't show stats for **abandoned branches** 4. It's not visible in **local git log** 5. **Requires specific platform** (GitHub/GitLab) ## My Ask: **Merge as experimental feature** - Behind feature flag - Document as "local development aid" - Gather user feedback ## Testing The PR includes: - ✅ Unit tests for message formatting - ✅ Integration tests for the full flow - ✅ Edge case coverage (empty commits, feature disabled, etc.) - ✅ Snapshot tests for output format ## My Questions 1. Is the **two-layer config approach** acceptable? (feature flag + git config) 2. Should stats be **appended** or **prepended** to the commit message? 3. Any concerns about the implementation approach? I'm happy to iterate on this based on your guidance. The core value I'm trying to add is **better local visibility** into AI contributions without disrupting existing workflows. Thanks again for building git-ai and considering this enhancement!
Author
Owner

@acunniffe commented on GitHub (Dec 30, 2025):

Hey @zaizyp - thanks for opening the PR - it's good work, but I'm still not sure if this makes sense. Git AI's accuracy is a big part of its value to teams and I don't think the description should be endorsed as a trustworthy place for this. Descriptions can be amended, merged weirdly during a rebase, etc. IMO this is the reason git puts the summary stats behind --stat instead of in the description. Git AI should do the same

btw if your original issue was having trouble remembering the sha, we support git refspecs which should make it easier.

git-ai stats head for last
git-ai stats head~n also works for past commits.

<!-- gh-comment-id:3699377288 --> @acunniffe commented on GitHub (Dec 30, 2025): Hey @zaizyp - thanks for opening the PR - it's good work, but I'm still not sure if this makes sense. Git AI's accuracy is a big part of its value to teams and I don't think the description should be endorsed as a trustworthy place for this. Descriptions can be amended, merged weirdly during a rebase, etc. IMO this is the reason git puts the summary stats behind `--stat` instead of in the description. Git AI should do the same btw if your original issue was having trouble remembering the sha, we support git refspecs which should make it easier. `git-ai stats head` for last `git-ai stats head~n` also works for past commits.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#109
No description provided.