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

Using Large Language Models for Commit Message Generation: A Preliminary Study

Linghao Zhang, Jingshu Zhao, Chong Wang, Peng Liang · DOI

Abstract

Writing high-quality Git commit messages is a critical yet often neglected aspect of software development. While automated tools have been developed to assist in this task, they frequently struggle with the semantic nuances of code changes. This study evaluates the efficacy of Large Language Models (LLMs)—specifically ChatGPT and Llama 2—in generating commit messages from code diffs using zero-shot prompting. Our results demonstrate that while automated metrics show LLMs are comparable to specialized baselines, human developers overwhelmingly prefer LLM-generated messages over both existing tools and original human-written messages.

Introduction

A well-crafted commit message serves as vital documentation, facilitating code audits, debugging, and collaboration. However, the manual process is time-consuming, leading many developers to provide cryptic or uninformative summaries. Previous attempts to automate this process relied on specialized "generation-based" or "retrieval-based" models. While these models can capture structural patterns, they often fail to grasp the underlying logic of a code change. This research investigates whether general-purpose LLMs can bridge this gap through zero-shot reasoning, requiring no task-specific training or examples.

Methodology

The researchers conducted a two-phase evaluation to compare LLMs against traditional specialized models.

Models and Baselines

The study evaluated three LLM configurations:

  • ChatGPT (gpt-3.5-turbo)
  • Llama 2 7B
  • Llama 2 70B

These were compared against five specialized baseline models, including CoDiSum and NNGen. The LLMs were prompted with a simple zero-shot instruction: "Your task is to write a short commit message accordingly," followed by the code diff.

Evaluation Strategy

  1. Automated Metrics: The models were evaluated using four variants of BLEU and Rouge-L. These metrics measure the linguistic similarity between the generated text and a "ground truth" (the original human-written message).
  2. Human Evaluation: To address the limitations of automated metrics, two researchers performed a blind review of 366 samples. For each code change, they evaluated eight candidate messages (from LLMs, baselines, and the original human author) in a randomized order to identify the highest quality message.

Dataset

The study utilized a dataset of 7,661 pairs of code diffs and human-written commit messages sourced from the top 1,000 Java projects on GitHub. For the human evaluation phase, a statistically representative sample of 366 pairs was used to ensure a 95% confidence level.

Key Results and Analysis

Human Preference and Quality

The human evaluation revealed a significant gap between LLM performance and human-written messages. LLMs were selected as the "best" message in 78% of the tested cases. Specifically, Llama 2 70B was preferred in 32.8% of cases, followed closely by ChatGPT at 31.8%. Notably, the original human-written messages were chosen as the best only 13.1% of the time, suggesting that LLMs are more consistent at capturing the essence of a code update than the developers themselves.

The "Ground Truth" Paradox

A critical insight from the study is the inherent flaw in using traditional metrics like BLEU or Rouge-L for this task. These metrics reward models for mimicking human-written messages. However, because human-written messages are often noisy or of low quality, an LLM that produces a clearer, more descriptive message may actually receive a lower score. Despite this, ChatGPT still outperformed specialized baselines on the B-NLTK metric, scoring 7.39 compared to CoDiSum’s 5.72.

Model Scaling

The performance difference between Llama 2 7B and 70B indicates that the ability to reason through code diffs scales with model size. The 70B parameter model consistently provided more accurate and contextually relevant summaries than its smaller counterpart.

Discussion and Limitations

While the results are promising, the study identifies several areas for future exploration:

  • Prompt Engineering: The study relied on basic zero-shot prompts. Techniques such as "Chain-of-Thought" prompting—where the model explains the code change before summarizing it—could potentially yield even higher quality results.
  • Scope: The evaluation was limited to the Java programming language and relatively small diffs. The performance of LLMs on multi-file commits or other programming languages remains to be fully explored.
  • Reproducibility: The non-deterministic nature of closed-source models like ChatGPT poses challenges for exact replication of results over time.

Conclusion

This preliminary study suggests that Large Language Models represent a significant leap forward in automated commit message generation. By moving beyond simple pattern matching to zero-shot reasoning, LLMs can produce documentation that human developers find more useful than original human-written messages. Future work will focus on integrating these capabilities directly into the software development lifecycle through IDE plugins and automated workflows.

Summary updated

BibTeX
@inproceedings{zhang2024using,
  author = {Linghao Zhang and Jingshu Zhao and Chong Wang and Peng Liang},
  title = {{Using Large Language Models for Commit Message Generation: A Preliminary Study}},
  booktitle = {SANER},
  year = {2024},
  doi = {10.1109/saner60148.2024.00020},
}
Figure