git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] git merge reports conflict when two branches add independent methods at the same location

From
GTGuo Tingsheng <coricraft16@outlook.com>
Date
Sep 12, 2025, 13:37 UTC
Message-ID
<SN6PR03MB4285B971FAD1CD485B9A8840AE08A@SN6PR03MB4285.namprd03.prod.outlook.com>
Hello Git developers,
I would like to report a potential issue in Git's merge behavior, where semantically independent changes at the same position are reported as a conflict, even though they could be merged automatically.
Environment:
- git version: 2.43.0
- OS: Ubuntu 24.04 LTS
Steps to reproduce:
1. Start with a file containing only:
   public class Calculator {
   }
2. On branch A, add a new method `add`:
   @@ -1,1 +1,3 @@
   public class Calculator {
   +    public static double add(double a, double b) {
   +        return a + b;
   +    }
3. On branch B, add a new method `subtract`:
   @@ -1,1 +1,3 @@
   public class Calculator {
   +    public static double subtract(double a, double b) {
   +        return a - b;
   +    }
4. Merge branch A and branch B.
Expected result:
- The merge should succeed automatically, producing a file that contains both methods (order does not matter).  
  For example:
   public class Calculator {
       public static double add(double a, double b) {
           return a + b;
       }
       public static double subtract(double a, double b) {
           return a - b;
       }
   }
Actual result:
- Git reports a conflict and aborts the merge, requiring manual conflict resolution.
Additional information:
- Although the two changes occur at the same location in the file, they are independent additions with no semantic overlap.
- It would be desirable for Git's merge algorithm to automatically combine such changes, as the final merged state is deterministic and conflict-free.
- This limitation may impact developer productivity in real-world projects where multiple contributors extend the same class or configuration file independently.

Thanks, Cori

Next: Elijah Newren
Message 1 of 3 in “[BUG] git merge reports conflict when two branches add independent methods at the same location”
  1. Guo TingshengSep 12, 2025
  2. Elijah NewrenSep 12, 2025
  3. Ben KnobleSep 13, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.