Leveraging Context-Aware Prompting for Commit Message Generation

Zhihua Jiang, Jianwei Chen, Dongning Rao, Guanghui YeEMNLP 2024

Introduction

Automated commit message generation aims to alleviate the burden on developers while maintaining high-quality project documentation. However, existing approaches often struggle with either "tunnel vision"—focusing solely on changed lines—or "information overload"—including too much irrelevant surrounding code. This paper presents COMMIT, a framework that utilizes program slicing and graph-based analysis to identify the optimal context for generating accurate and concise commit messages.

Methodology: The COMMIT Framework

The core innovation of COMMIT lies in its ability to move beyond physical proximity when selecting context. Instead of a simple window of lines around a change, COMMIT employs Code Property Graphs (CPGs). A CPG integrates Abstract Syntax Trees (AST), Control Flow Graphs (CFG), and Program Dependence Graphs (PDG) to map the semantic relationships within the code.

The COMMIT pipeline: from data collection and graph construction to context extraction and message generation.

As shown in the pipeline overview, COMMIT performs program slicing to follow the logic of a change. For instance, if a variable is modified, the system identifies its initialization and usage points, regardless of their physical distance from the edit. These relationships are synthesized into an Added-Deleted Context Graph (ADCG), which captures the essential dependencies of the diff.

Detailed construction of the Added-Deleted Context Graph (ADCG) from the original code diff and constituent CPGs.

This curated "slice" of code is then formatted using a continuous prompt template and fed into CodeT5+, a pre-trained model optimized for code understanding. Research found that a dependency depth of 3 was optimal; looking deeper introduced noise that degraded performance.

The CODEC Dataset

To support this research, the authors introduced CODEC (COntext and metaData Enhanced Code dataset). Derived from high-star Java repositories on GitHub, CODEC contains approximately 10,300 training samples. Unlike previous datasets such as NNGen or MCMD, CODEC is uniquely enriched with semantic context and metadata, making it a "denser" and higher-quality resource for training context-aware models.

Results and Evaluation

COMMIT was evaluated against 16 baseline models, including Large Language Models (LLMs) like GPT-3.5 and CodeLlama. COMMIT outperformed all competitors across standard NLP metrics, achieving a BLEU-4 of 13.13, a METEOR of 12.48, and a ROUGE-L of 24.05.

Human evaluations confirmed these findings, with professional developers preferring COMMIT’s messages in 33.2% of cases—the highest preference rate among all tested systems. Notably, specialized models like COMMIT proved more effective than general-purpose LLMs, which often lacked technical precision or produced overly verbose summaries.

Conclusion

The COMMIT framework demonstrates that precise code analysis and semantic context selection are more critical than raw model size for commit message generation. By leveraging graph-based program slicing, COMMIT provides a scalable way to generate high-quality documentation. Future work will focus on extending support to languages like Python and C++ and further optimizing the computational efficiency of graph construction.

Summary updated

BibTeX
@inproceedings{jiang2024leveraging,
  author = {Zhihua Jiang and Jianwei Chen and Dongning Rao and Guanghui Ye},
  title = {{Leveraging Context-Aware Prompting for Commit Message Generation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.749},
}
Figure