{"thread":{"id":"64135","subject":"[BUG] git merge sometimes loses changes from one branch","startedAt":"2025-09-12T13:40:59Z","lastAt":"2025-10-28T16:12:35Z","messageCount":3,"participants":["Guo Tingsheng","Elijah Newren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"526188","messageId":"SN6PR03MB4285CA9885AE7952EEF762E1AE08A@SN6PR03MB4285.namprd03.prod.outlook.com","threadId":"64135","inReplyTo":null,"subject":"[BUG] git merge sometimes loses changes from one branch","fromName":"Guo Tingsheng","fromEmail":"coricraft16@outlook.com","sentAt":"2025-09-12T13:40:57Z","receivedAt":"2025-09-12T13:40:59Z","isPatch":false,"sender":{"key":"coricraft16@outlook.com","avatar":null},"body":"Hello Git developers,\n\nI would like to report a potential issue in Git's merge behavior, where changes from one branch may be lost even when the other branch does not modify the same location.\n\nEnvironment:\n- git version: 2.43.0\n- OS: Ubuntu 24.04 LTS\n\nSteps to reproduce:\n1. On branch A, modify a file at a certain location:\n\n   @@ -1026,7 +1028,9 @@\n   public final class AutoBuilderCompilationTest {\n                \"  }\",\n                \"}\"); \n        Compilation compilation =\n   -        javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n   +        javac()\n   +            .withProcessors(new AutoBuilderProcessor())\n   +            .compile(javaFileObject);\n        assertThat(compilation).failed();\n        assertThat(compilation)\n            .hadErrorContaining(\n\n2. On branch B, make no changes to this location.\n\n3. Merge branch A and branch B.\n\nExpected result:\n- The merge should retain the changes made in branch A:\n\n   @@ -1026,7 +1028,9 @@\n   public final class AutoBuilderCompilationTest {\n                \"  }\",\n                \"}\"); \n        Compilation compilation =\n   -        javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n   +        javac()\n   +            .withProcessors(new AutoBuilderProcessor())\n   +            .compile(javaFileObject);\n        assertThat(compilation).failed();\n        assertThat(compilation)\n            .hadErrorContaining(\n\nActual result:\n- Git sometimes produces a merged result where the modification from branch A is lost, yielding:\n\n   @@ -1026,7 +1028,9 @@\n   public final class AutoBuilderCompilationTest {\n                \"  }\",\n                \"}\"); \n        Compilation compilation =\n           javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n        assertThat(compilation).failed();\n        assertThat(compilation)\n            .hadErrorContaining(\n\nAdditional information:\n- This issue occurs even when the other branch (B) does not modify the same location.\n- It appears to happen non-deterministically and may lead to subtle bugs in real-world merges.\n\nThanks,\nCori\n"},{"id":"526237","messageId":"CABPp-BGeZ6no5LdBGKjykQLqUHRjFis7ZtGdEwnzg0gy_CkLqA@mail.gmail.com","threadId":"64135","inReplyTo":"SN6PR03MB4285CA9885AE7952EEF762E1AE08A@SN6PR03MB4285.namprd03.prod.outlook.com","subject":"Re: [BUG] git merge sometimes loses changes from one branch","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2025-09-12T22:56:55Z","receivedAt":"2025-09-12T22:57:07Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, Sep 12, 2025 at 6:41 AM Guo Tingsheng <CoriCraft16@outlook.com> wrote:\n>\n> Hello Git developers,\n>\n> I would like to report a potential issue in Git's merge behavior, where changes from one branch may be lost even when the other branch does not modify the same location.\n>\n> Environment:\n> - git version: 2.43.0\n> - OS: Ubuntu 24.04 LTS\n>\n> Steps to reproduce:\n> 1. On branch A, modify a file at a certain location:\n>\n>    @@ -1026,7 +1028,9 @@\n>    public final class AutoBuilderCompilationTest {\n>                 \"  }\",\n>                 \"}\");\n>         Compilation compilation =\n>    -        javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n>    +        javac()\n>    +            .withProcessors(new AutoBuilderProcessor())\n>    +            .compile(javaFileObject);\n>         assertThat(compilation).failed();\n>         assertThat(compilation)\n>             .hadErrorContaining(\n>\n> 2. On branch B, make no changes to this location.\n>\n> 3. Merge branch A and branch B.\n>\n> Expected result:\n> - The merge should retain the changes made in branch A:\n>\n>    @@ -1026,7 +1028,9 @@\n>    public final class AutoBuilderCompilationTest {\n>                 \"  }\",\n>                 \"}\");\n>         Compilation compilation =\n>    -        javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n>    +        javac()\n>    +            .withProcessors(new AutoBuilderProcessor())\n>    +            .compile(javaFileObject);\n>         assertThat(compilation).failed();\n>         assertThat(compilation)\n>             .hadErrorContaining(\n>\n> Actual result:\n> - Git sometimes produces a merged result where the modification from branch A is lost, yielding:\n>\n>    @@ -1026,7 +1028,9 @@\n>    public final class AutoBuilderCompilationTest {\n>                 \"  }\",\n>                 \"}\");\n>         Compilation compilation =\n>            javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n>         assertThat(compilation).failed();\n>         assertThat(compilation)\n>             .hadErrorContaining(\n>\n> Additional information:\n> - This issue occurs even when the other branch (B) does not modify the same location.\n> - It appears to happen non-deterministically and may lead to subtle bugs in real-world merges.\n\nMy only guess here would be having a non-unique merge-base, where one\nof the merge bases also introduced this change, so that it appears\nthat A made no change relative to the consolidated merge base while\nalso making it look like branch B undid the change relative to that\nconsolidated merge base.  But, that's a wild guess and I have no idea\nif that's related to what you're seeing or if there's some unrelated\nissue at play.\n\nCan you create a testcase to reproduce this, either a repository that\nothers can clone together with the commands to trigger it, or a bunch\nof commands to both create a simple repository and demonstrate the\nissue?\n"},{"id":"529797","messageId":"SN6PR03MB4285533B67E31D36172A4C34AEFDA@SN6PR03MB4285.namprd03.prod.outlook.com","threadId":"64135","inReplyTo":"CABPp-BGeZ6no5LdBGKjykQLqUHRjFis7ZtGdEwnzg0gy_CkLqA@mail.gmail.com","subject":"回复: [BUG] git merge sometimes loses changes from one branch","fromName":"Guo Tingsheng","fromEmail":"coricraft16@outlook.com","sentAt":"2025-10-28T16:12:33Z","receivedAt":"2025-10-28T16:12:35Z","isPatch":false,"sender":{"key":"coricraft16@outlook.com","avatar":null},"body":"Hello Git developers,\n\nI would like to report a potential issue in Git’s merge behavior, where\nchanges from one branch may be lost even when the other branch does not\nmodify the same location.\n\nTo make it easier to reproduce, I have open-sourced this example in a public repository:\nRepository: https://github.com/CoriWork/bug-replay.git\n\nYou can clone the repository and follow the README.md to replay the bug!\n\n---\n\nEnvironment:\n- Git version: 2.43.0\n- OS: Ubuntu 24.04 LTS\n\n---\n\nSteps to reproduce:\n1. On branch B, modify a file at a certain location:\n\n@@ -1068,9 +1026,7 @@ public final class AutoBuilderCompilationTest {\n             \"  }\",\n             \"}\");\n     Compilation compilation =\n-        javac()\n-            .withProcessors(new AutoBuilderProcessor())\n-            .compile(javaFileObject);\n+        javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n     assertThat(compilation).failed();\n     assertThat(compilation)\n         .hadErrorContaining(\n\n2. On branch A, make no changes to this location.\n\n3. Merge branch A and branch B.\n\n---\n\nExpected result:\nThe merge should retain the change made in branch B:\n\n@@ -1068,9 +1026,7 @@ public final class AutoBuilderCompilationTest {\n             \"  }\",\n             \"}\");\n     Compilation compilation =\n-        javac()\n-            .withProcessors(new AutoBuilderProcessor())\n-            .compile(javaFileObject);\n+        javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);\n     assertThat(compilation).failed();\n     assertThat(compilation)\n         .hadErrorContaining(\n\nActual result:\nGit sometimes produces a merged result where the modification from branch A\nis lost, yielding:\n\n   @@ -1026,7 +1028,9 @@\n   public final class AutoBuilderCompilationTest {\n                \"  }\",\n                \"}\");\n       Compilation compilation =\n           javac()\n            .withProcessors(new AutoBuilderProcessor())\n            .compile(javaFileObject);\n\n---\n\nAdditional information:\n- This issue occurs even when branch B does not modify the same location.\n- It appears to happen deterministically under a specific construction that\n  splits one patch into two disjoint sets of hunks, applies them separately\n  to create two branches, and then merges them back.\n- The merged result can differ from the expected content of the original commit.\n\nThank you for your time and your work maintaining Git.\n\nBest regards,  \nGuo Tingsheng  \n< CoriCraft16@outlook.com >\n"}]}