# [BUG] Git merge produces inconsistent indentation in merged result

2 messages from 2025-09-12 to 2025-09-12. Participants: Guo Tingsheng, Elijah Newren.
Thread: https://gitlist.dev/t/64132

## Guo Tingsheng, 2025-09-12 13:13

Subject: [BUG] Git merge produces inconsistent indentation in merged result
Message-ID: <SN6PR03MB428572C742338251D0399FDFAE08A@SN6PR03MB4285.namprd03.prod.outlook.com>
URL: https://gitlist.dev/e/SN6PR03MB428572C742338251D0399FDFAE08A%40SN6PR03MB4285.namprd03.prod.outlook.com

```
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, 2025-09-12 22:56

Subject: Re: [BUG] Git merge produces inconsistent indentation in merged result
Message-ID: <CABPp-BHYEYgqo=G8q2XKReNn6PM+FWn1_8qfKq-ONS6pXXeN2A@mail.gmail.com>
URL: https://gitlist.dev/e/CABPp-BHYEYgqo%3DG8q2XKReNn6PM%2BFWn1_8qfKq-ONS6pXXeN2A%40mail.gmail.com
In-Reply-To: <SN6PR03MB428572C742338251D0399FDFAE08A@SN6PR03MB4285.namprd03.prod.outlook.com>

```
On Fri, Sep 12, 2025 at 6:14 AM Guo Tingsheng <CoriCraft16@outlook.com> wrote:
>
> 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?

```
