threads / bug / 64132

[BUG] Git merge produces inconsistent indentation in merged result

Subject: [BUG] Git merge produces inconsistent indentation in merged result

## tl;dr

2 messages between Sep 12, 2025 and Sep 12, 2025.

replies: 1people: 2as markdown or json

Guo Tingsheng· Sep 12, 2025, 13:13 UTC · lore
Hello Git developers,
I would like to report a potential formatting issue I encountered when testing Git merges.
Environment:
- git version: 2.43.0
- OS: Ubuntu 24.04 LTS 
Steps to reproduce:
1. Start from a commit containing the following method:
   public void process() {
       if (flag) {
           execute();
       }
   }
2. On branch A, modify the code by adding a new conditional block with indentation consistent with the surrounding style:
   public void process() {
       if (flag) {
           execute();
       }
       if (shouldLog) {
           logger.log("Action executed.");
       }
   }
3. On branch B, make no changes to this function.
4. Merge branch A and branch B using:
   git merge A
Expected result:
- The merged file should retain the indentation style introduced by branch A:
   public void process() {
       if (flag) {
           execute();
       }
       if (shouldLog) {
           logger.log("Action executed.");
       }
   }
Actual result:
- Git reduces the indentation of the newly added lines, producing inconsistent formatting:
   public void process() {
       if (flag) {
           execute();
       }
   if (shouldLog) {
       logger.log("Action executed.");
   }
   }
Additional information:
- This issue appears to occur non-deterministically across different test cases.
- It does not seem related to core.whitespace or space-change options, but instead to how Git decides indentation for newly introduced blocks.
- The problem was reproduced using multiple merge strategies (ort, recursive).

Thanks, Cori

Elijah Newren· Sep 12, 2025, 22:56 UTC · re: Guo Tingsheng · lore

Re: [BUG] Git merge produces inconsistent indentation in merged result

On Fri, Sep 12, 2025 at 6:14 AM Guo Tingsheng <CoriCraft16@outlook.com> wrote:
Show 62 quoted lines
>
> Hello Git developers,
>
> I would like to report a potential formatting issue I encountered when testing Git merges.
>
> Environment:
> - git version: 2.43.0
> - OS: Ubuntu 24.04 LTS
>
> Steps to reproduce:
> 1. Start from a commit containing the following method:
>
>    public void process() {
>        if (flag) {
>            execute();
>        }
>    }
>
> 2. On branch A, modify the code by adding a new conditional block with indentation consistent with the surrounding style:
>
>    public void process() {
>        if (flag) {
>            execute();
>        }
>        if (shouldLog) {
>            logger.log("Action executed.");
>        }
>    }
>
> 3. On branch B, make no changes to this function.
>
> 4. Merge branch A and branch B using:
>    git merge A
>
> Expected result:
> - The merged file should retain the indentation style introduced by branch A:
>
>    public void process() {
>        if (flag) {
>            execute();
>        }
>        if (shouldLog) {
>            logger.log("Action executed.");
>        }
>    }
>
> Actual result:
> - Git reduces the indentation of the newly added lines, producing inconsistent formatting:
>
>    public void process() {
>        if (flag) {
>            execute();
>        }
>    if (shouldLog) {
>        logger.log("Action executed.");
>    }
>    }
>
> Additional information:
> - This issue appears to occur non-deterministically across different test cases.
> - It does not seem related to core.whitespace or space-change options, but instead to how Git decides indentation for newly introduced blocks.
> - The problem was reproduced using multiple merge strategies (ort, recursive).

I've never seen or heard of such a thing before; can you create a testcase to reproduce it, either a repository that others can clone together with the commands to trigger it, or a bunch of commands to both create a simple repository and demonstrate the issue?

← back to recent threads