[BUG] Git merge produces inconsistent indentation in merged result
- From
- Guo Tingsheng <coricraft16@outlook.com>
- Date
- Sep 12, 2025, 13:13 UTC
- Message-ID
- <SN6PR03MB428572C742338251D0399FDFAE08A@SN6PR03MB4285.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