代码差异表示在代码提交信息生成中的有效性实证研究
作者:
作者单位:

作者简介:

通讯作者:

中图分类号:

TP311

基金项目:

国家重点研发计划战略性科技创新合作项目(2024YFE0204200); 国家自然科学基金重点项目( 62232001)


Empirical Study on Effectiveness of Code Difference Representations in Commit Message Generation of Code
Author:
Affiliation:

Fund Project:

  • 摘要
  • |
  • 图/表
  • |
  • 访问统计
  • |
  • 参考文献
  • |
  • 相似文献
  • |
  • 引证文献
  • |
  • 资源附件
  • |
  • 文章评论
    摘要:

    提交信息生成(commit message generation, CMG)是软件演化与维护领域的重要任务, 其目标是依据给定的代码差异自动生成提交信息. 目前CMG方法普遍基于Git原生差异格式GitDiff构造输入, 该格式通过固定大小的上下文窗口展示变更行附近的代码片段. 然而, 代码差异的表示方式并非唯一, 通过扩大上下文范围可以构造信息更完整的代码差异表示. 具体地, 构建两种不同上下文范围的差异表示形式, 并围绕差异表示形式对CMG质量的影响开展实证研究. 实验使用现有CMG研究常用的MCMD数据集, 选取6种代表性CMG方法, 使用多种度量来分析3种代码差异表示对于CMG方法的效果影响. 实验结果表明, 尽管 GitDiff 在整体平均指标上略占优势, 但其样本胜率(41.5%)并未构成压倒性领先, 表明不同差异表示在不同代码语境下存在明显性能差异. 此外, 差异表示的选择会影响CMG模型性能比较结论, 在25%–50%的样本中, 基于GitDiff得到的模型优劣排序在切换至其他表示后会发生变化, 说明仅依赖单一代码差异表示所得模型性能结论可能存在偏差. 进一步研究发现, 当变更行依赖的关键语义单元超出GitDiff固定上下文窗口的覆盖范围时, 补全这些缺少的关键语义单元可以在一定程度上提升提交信息生成质量. 对此类场景进行系统归纳, 可为实践中代码差异表示的选择提供参考.

    Abstract:

    Commit message generation (CMG) is an important task in software evolution and maintenance, aiming to automatically generate commit messages based on given code differences. Existing CMG approaches predominantly rely on inputs constructed from the native Git difference format (GitDiff), which presents code changes along with their surrounding context within a fixed-size window. However, there is no single way to represent code differences. Expanding the context scope enables the construction of more informative representations. Specifically, this study constructs two alternative difference representations with different context ranges and conducts an empirical study on how difference representation affects CMG quality. Experiments are conducted on the widely used MCMD dataset, involving six representative CMG approaches and multiple evaluation metrics to systematically analyze the impact of three difference representations on model performance. The results show that although GitDiff performs slightly better on average across the evaluation metrics, its sample-level win rate (41.5%) does not constitute a dominant advantage, indicating substantial performance variation across different code contexts. Furthermore, the choice of difference representation can influence conclusions about the relative performance of CMG models. For 25%–50% of the samples, the relative ranking of models based on GitDiff changes when switching to other representations, suggesting that conclusions drawn from a single difference representation may be biased. Further analysis reveals that when key semantic units on which the changed lines depend fall outside the fixed context window of GitDiff, supplementing these missing semantic units can improve the quality of generated commit messages to some extent. This study systematically characterizes such scenarios, providing a reference for selecting code difference representations in practice.

    参考文献
    相似文献
    引证文献
引用本文

李旻灿,王国庆,赵逸凡,郝丹.代码差异表示在代码提交信息生成中的有效性实证研究.软件学报,,():1-28

复制
相关视频

分享
文章指标
  • 点击次数:
  • 下载次数:
  • HTML阅读次数:
  • 引用次数:
历史
  • 收稿日期:2026-04-23
  • 最后修改日期:2026-06-11
  • 录用日期:
  • 在线发布日期: 2026-11-04
  • 出版日期:
文章二维码
您是第位访问者
版权所有:中国科学院软件研究所 京ICP备05046678号-3
地址:北京市海淀区中关村南四街4号,邮政编码:100190
电话:010-62562563 传真:010-62562533 Email:jos@iscas.ac.cn
技术支持:北京勤云科技发展有限公司

京公网安备 11040202500063号