Abstract
Commit messages concisely describe code changes in natural language and are important for software maintenance. Several approaches have been proposed to automatically generate commit messages, but they still suffer from critical limitations, such as time-consuming training and poor generalization ability. To tackle these limitations, we propose to borrow the weapon of large language models (LLMs) and in-context learning (ICL). Our intuition is based on the fact that the training corpora of LLMs contain extensive code changes and their pairwise commit messages, which makes LLMs capture the knowledge about commits, while ICL can exploit the knowledge hidden in the LLMs and enable them to perform downstream tasks without model tuning. However, it remains unclear how well LLMs perform on commit message generation via ICL. In this paper, we conduct an empirical study to investigate the capability of LLMs to generate commit messages via ICL. Specifically, we first explore the impact of different settings on the performance of ICL-based commit message generation. We then compare ICL-based commit message generation with state-of-the-art approaches on a popular multilingual dataset and a new dataset we created to mitigate potential data leakage. The results show that ICL-based commit message generation significantly outperforms state-of-the-art approaches on subjective evaluation and achieves better generalization ability. We further analyze the root causes for LLM's underperformance and propose several implications, which shed light on future research directions for using LLMs to generate commit messages.
Introduction
Writing high-quality commit messages is a tedious but crucial part of software maintenance. While automated commit message generation tools exist, the current state-of-the-art relies on learning-based approaches, such as fine-tuning CodeT5. These approaches face significant challenges: they are resource-intensive to train, rely on noisy and low-quality open-source commit datasets, and often suffer from poor generalization when applied to new projects or programming languages. This study investigates whether off-the-shelf Large Language Models (LLMs) can bypass fine-tuning through In-Context Learning (ICL), providing a few examples in the prompt to generate high-quality commit messages.
Methodology
The research systematically evaluates the performance of LLMs on commit message generation using ICL across several variables: prompt design, the number of demonstrations (few-shot examples), and demonstration selection methods (random vs. kNN retrieval). The study evaluates six LLMs, including general models like GPT-3.5-Turbo and Claude 3, and code-specific models like DeepSeek-Coder-V2, against three state-of-the-art fine-tuned baselines (NNGen, CCT5, COME).
To ensure robust evaluation, two datasets were used: the popular MCMD benchmark and a newly created MCMD-New dataset. MCMD-New includes commits post-January 2022 (MCMD-NT) and five new programming languages (MCMD-NL) to mitigate potential data leakage from the LLMs' training sets and test generalization.
Key Insights and Results
A primary finding is that few-shot examples act as prompt stabilizers. While zero-shot performance is highly sensitive to prompt wording, adding demonstrations makes the model more robust. However, there is a "Goldilocks" zone for demonstrations; performance typically peaks at 16 examples. As shown in the performance analysis across metrics, increasing the demonstration number to 128 can actually degrade quality, likely due to the introduction of noise from less relevant examples.
Surprisingly, general LLMs like GPT-3.5-Turbo and DeepSeek-V2-Chat outperformed code-specific models. This suggests that code-specific LLMs, while proficient in static code, may struggle more with the natural language mapping required to describe code changes. Furthermore, the study highlights that traditional objective metrics like BLEU and ROUGE-L can be misleading. Fine-tuned models often score higher by mimicking low-quality ground-truth references, whereas human and LLM-as-a-judge evaluations strongly prefer the more informative outputs of LLMs. In fact, a manual review revealed that 58.5% of cases where LLMs scored zero on objective metrics were false positives—the generated messages were actually high-quality.
Conclusion and Future Work
The study demonstrates that ICL-based commit message generation significantly outperforms traditional approaches in subjective quality and generalization. Future work should focus on developing IDE-integrated tools for seamless drafting and creating higher-quality datasets. Using LLMs to generate high-quality pseudo-labels could help replace noisy ground-truth data, and pre-training models specifically on code diffs remains a promising research direction.
Summary updated