Abstract
Automated Commit Message Generation (CMG) typically treats the task as a translation problem, using code diffs as the primary input. However, diffs often provide a "peephole" view that lacks the context necessary to explain the intent or impact of a change. We present C3Gen, a Retrieval-Augmented Generation (RAG) framework that retrieves relevant code snippets from the broader repository to enrich the generation process. Evaluated on a new, high-quality benchmark, ApacheCM, C3Gen demonstrates significant improvements in message completeness and informativeness compared to naive models.
1. Introduction
Writing descriptive commit messages is essential for software maintenance, yet it remains a task frequently neglected by developers. Existing CMG tools often struggle because they rely solely on the code diff—the specific lines added or removed. This approach fails to capture the "global" context of a repository, such as how a modified function is invoked elsewhere in the system. Without this context, AI models can describe what changed but often fail to explain why it changed or what its broader implications are.
2. The C3Gen Framework
To bridge this context gap, we developed C3Gen, a three-stage framework designed to provide Large Language Models (LLMs) with repository-level intelligence during the generation process.
2.1 CSG Construction
The process begins with static analysis using the tree-sitter library to build Code Structure Graphs (CSGs). These graphs map the relationships between classes and functions across the entire repository.
2.2 Diff-based Augmentation
When a new commit is processed, C3Gen parses the diff to identify the specific entities (functions or classes) that were modified. These entities are compiled into a ModifiedEntityList.
2.3 Relevant Code Snippet Extraction
Using the CSG, C3Gen searches the repository for code that interacts with the modified entities. These snippets are retrieved and included in the LLM prompt alongside the raw diff, providing the model with a comprehensive view of the code's usage and dependencies.
3. The ApacheCM Dataset
A significant contribution of this study is the ApacheCM benchmark. Recognizing that previous datasets were often "noisy" (containing bot messages, reverts, or merges), we curated over 230,000 commits from 50 top-tier Apache projects. This dataset includes rich metadata and was strictly filtered to ensure high-quality, human-written ground truth messages for training and evaluation.
4. Results and Discussion
We evaluated C3Gen against naive (diff-only) versions of state-of-the-art models, including GPT-4o and DeepSeek-R1.
4.1 The Metric Trap
A key finding of our research is the "Metric Trap": traditional NLP metrics like BLEU and ROUGE are poor proxies for commit message quality. Because these metrics rely on word-for-word overlap, they often penalize semantically superior messages that use different terminology than the original developer.
4.2 Human Evaluation
While objective metric improvements were modest (e.g., a 2.4% increase in BLEU for GPT-4o), human evaluations revealed a much more significant impact. Graders found that C3Gen-generated messages were consistently more Complete, scoring roughly 5% higher in completeness across all tested models. Interestingly, LLM-generated messages often scored higher than the original human-written messages in terms of clarity and detail.
5. Limitations and Future Work
Despite its successes, C3Gen faces challenges with "retrieval noise," where irrelevant code snippets can distract the model and lead to minor hallucinations. Furthermore, LLMs often struggle to match the specific stylistic shorthand of individual developers. Future work will focus on refining retrieval filters to minimize noise and expanding the ApacheCM dataset to encompass a wider variety of programming languages and repository types.
6. Conclusion
C3Gen demonstrates that repository-level context is a vital component for high-quality automated commit message generation. By moving beyond the "peephole" view of code diffs, RAG-based frameworks can provide the necessary context to generate messages that are truly useful for long-term software maintenance.
Summary updated