NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

RAG-Enhanced Commit Message Generation

Linghao Zhang, Hongyi Zhang, Chong Wang, Peng LiangarXiv 2024 · DOI

Introduction In software development, commit messages serve as a critical record of changes, yet they are notoriously difficult to maintain. Developers often view writing them as a tedious chore, frequently resulting in vague or unhelpful descriptions like "fixed bug" or "updated files." Automated Commit Message Generation (CMG) seeks to alleviate this burden by translating code diffs into descriptive natural language. However, standard AI models often struggle with the stylistic nuances of different projects.

The REACT concept: Using a similar past commit as a guide for generating new messages.

The paper "RAG-Enhanced Commit Message Generation" introduces REACT, a Retrieval-Augmented Generation (RAG) framework designed to provide AI models with a "cheat sheet" of relevant historical examples. By showing a model how a similar change was described in the past, REACT significantly bridges the gap between automated output and human-quality documentation.

The REACT Framework The REACT framework follows a structured three-phase pipeline to transform raw code changes into informative commit messages.

The three-stage architecture of REACT: Retrieve, Augment, and Generate.
  1. Retrieve: When a developer submits a new code change (the "query diff"), REACT searches a massive database of over 1.6 million historical commits. It employs a hybrid retriever that combines lexical matching (BM25) to find keyword overlaps with semantic matching (CodeT5+ encoder) to understand the underlying logic of the code.
  2. Augment: The system identifies the most similar historical "exemplar"—a pair consisting of a similar code diff and its original commit message. This exemplar is then packaged with the new query diff. For Large Language Models (LLMs) like Llama 3, this is presented as a "one-shot" prompt, providing a clear pattern for the model to follow.
  3. Generate: The combined input is fed into a generator. The researchers tested both fine-tuned Pre-trained Language Models (PLMs) like CodeT5 and off-the-shelf LLMs like ChatGPT and Llama 3 using in-context learning.

Datasets and Evaluation The framework was evaluated using a benchmark of over 90,000 Java code-diff pairs from top GitHub projects. To test real-world adaptability, the authors also conducted a case study on the Electron project, scraping over 3,600 pairs to see if REACT could learn project-specific conventions (such as specific prefixing styles) simply by retrieving historical commits from that same project.

Key Results and Insights The integration of RAG proved to be a powerful "force multiplier" for model performance:

  • State-of-the-Art Performance: CodeT5 enhanced with REACT achieved a BLEU score of 9.68, representing a 55% improvement over its performance without retrieval and setting a new state-of-the-art.
  • Transformative Gains for LLMs: Llama 3 saw its performance more than double, with its BLEU score jumping from 2.40 to 4.84 (a 102% increase) simply by being shown a single relevant example via REACT.
  • Efficiency: Fine-tuning a PLM with REACT (CodeT5) proved highly accessible, requiring only 8 hours of training on a single consumer-grade GPU (RTX 4090).

Conclusion REACT demonstrates that the key to better automated commit messages isn't just larger models, but better context. By providing models with relevant historical examples, the framework transforms the generation task from abstract guessing into informed imitation. While currently focused on Java, the success of REACT suggests a promising path forward for multi-language support and the integration of even richer context, such as issue tracker data, to further refine automated software documentation.

Summary updated

BibTeX
@misc{zhang2024rag,
  author = {Linghao Zhang and Hongyi Zhang and Chong Wang and Peng Liang},
  title = {{RAG-Enhanced Commit Message Generation}},
  year = {2024},
  eprint = {2406.05514},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.05514},
}
Figure