Can Pre-trained Language Models be Used to Resolve Textual and Semantic Merge Conflicts?

Jialu Zhang, Todd Mytkowicz, Mike Kaufman, Ruzica Piskac, Shuvendu K. LahiriarXiv 2021 · OpenReview

Abstract

This paper explores the utility of Large Language Models (LLMs) in resolving complex software merge conflicts. While standard version control tools handle simple textual merges, they often fail on semantic conflicts where code integrates cleanly but breaks the build. We present Gmerge, a tool leveraging GPT-3 and k-shot learning to automate conflict resolution. Gmerge achieves 64.6% accuracy on semantic conflicts within the Microsoft Edge codebase, significantly outperforming specialized symbolic reasoning tools.

Introduction

In large-scale collaborative software engineering, integrating changes from disparate branches is a frequent and error-prone task. Standard tools effectively manage simple textual overlaps, but "semantic" conflicts—where the merged code is syntactically correct but logically broken—remain a major challenge. These are particularly prevalent in "divergent forks," such as Microsoft Edge, which must continuously merge updates from the upstream Chromium project.

The Challenge of Semantic Conflicts

A textual merge conflict occurs when two developers modify the same line of code. A semantic conflict is more subtle: for instance, an upstream change might rename a function, while a downstream change adds a new call to the original function name. The merge succeeds at the text level, but the code fails to compile. Resolving these requires developers to manually trace the root cause through extensive commit histories, a process that is both time-consuming and tedious.

Methodology: The Gmerge Pipeline

The researchers developed Gmerge, a language-agnostic tool designed to resolve conflicts without the need for extensive task-specific fine-tuning. The Gmerge workflow consists of two primary phases:

  1. Data Curation: Gmerge uses compiler error messages to identify relevant keywords. It then filters the repository's commit history to extract only the upstream changes related to those keywords, formatting them into a structured JSON representation.
  2. Prompt Engineering: Given the limited context window of LLMs, Gmerge employs heuristics to select the most relevant "shots" (examples) for k-shot learning. The model is provided with a few "Conflict -> Resolution" pairs to guide its inference.
The Gmerge pipeline: from data curation and prompt engineering to resolution via GPT-3.

Evaluation and Datasets

Gmerge was evaluated against three benchmarks:

  • Microsoft Edge Semantic Conflicts: 379 real-world conflicts resulting in compiler errors (e.g., err_no_member).
  • Microsoft Edge Textual Conflicts: 122 header file conflicts and 38 macro-related conflicts.
  • DeepMerge Benchmark: A public dataset of thousands of JavaScript textual conflicts from GitHub.

Key Results

The evaluation demonstrated that general-purpose LLMs can surpass specialized symbolic tools in resolving complex conflicts. Gmerge achieved 64.6% accuracy on semantic conflicts in Microsoft Edge, compared to just 25.9% for the previous state-of-the-art tool, Transformation.Text.

Accuracy rates of Gmerge (GPT-3 and GPT-J) compared to baselines across multiple model queries.

Key findings include:

  • Model Scaling: GPT-3 (175B parameters) significantly outperformed the smaller GPT-J (6B parameters), particularly as the number of allowed attempts (queries) increased.
  • The "Long Tail": Gmerge proved more effective than specialized models on large conflicts (over 8 lines), benefiting from the LLM's broader reasoning capabilities.
  • One-Shot Learning: Moving from zero-shot to one-shot learning provided a substantial boost in accuracy, as the model quickly adapted to the specific "edit" task from a single example.

Conclusion

Gmerge demonstrates that pre-trained LLMs are highly effective at resolving both textual and semantic merge conflicts. By bypassing the need for complex Domain-Specific Languages (DSLs) or massive labeled datasets, Gmerge offers a scalable solution for maintaining divergent forks. Future work will focus on overcoming token limits and incorporating project-specific "tribal knowledge" into the resolution process.

Summary updated

BibTeX
@misc{zhang2021can,
  author = {JIALU ZHANG and Todd Mytkowicz and Mike Kaufman and Ruzica Piskac and Shuvendu K. Lahiri},
  title = {{Can Pre-trained Language Models be Used to Resolve Textual and Semantic Merge Conflicts?}},
  year = {2021},
  eprint = {2111.11904},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2111.11904},
}
Figure