Chapter 20Lesson 03~130 minutes

Merge Algorithms, Conflict Engineering, rerere, and Custom Merge Drivers: Configuration, Design Choices, and Tradeoffs

Design merge policy around conflict presentation, rerere staging, renormalization, attributes, generated and lock files, strategy options, and portable custom-driver provisioning.

ConfigurationNormalizationGenerated filesDriver policy

Learning objectives

  • Choose merge/diff3/zdiff3 presentation without confusing it with merge semantics.
  • Select rerere.enabled and rerere.autoUpdate policy according to validation risk.
  • Use merge.renormalize only for understood canonicalization transitions.
  • Separate tracked driver selection from executable driver configuration/runtime.
  • Choose generated/lock-file policies from format semantics rather than convenience.

1. Merge configuration should expose intent, not hide difficult decisions

Every setting below changes presentation, reuse, normalization, or file-level merge behavior. Before enabling one, state the repository problem and the validation mechanism. “Fewer conflicts” is not sufficient because fewer prompts can also mean more silent mismerges.

2. Inspect effective configuration and attributes

git config --list --show-origin --show-scope
git config --show-origin --get merge.conflictStyle
git config --show-origin --get rerere.enabled
git config --show-origin --get rerere.autoUpdate
git config --show-origin --get merge.renormalize
git check-attr merge text eol -- path/to/file

Tracked attributes travel in history. Local merge-driver commands and repository-local rerere settings do not. System/global config can affect many repositories and should not be changed casually in training.

3. merge.conflictStyle changes conflict presentation

Style Presentation Purpose
merge ours/theirs markers Compact default
diff3 adds explicit base block Understand what both sides changed from
zdiff3 base block plus reduced matching edge context Base insight with less clutter
git config --local merge.conflictStyle zdiff3

The underlying stage-1/2/3 entries are unchanged.

4. rerere policy separates recording from automatic staging

git config --local rerere.enabled true
git config --local rerere.autoUpdate false

This setting records/reuses matching resolutions but preserves a review checkpoint. In highly repetitive, thoroughly tested workflows, autoupdate may be acceptable, but the team should document why staging a reused decision automatically is safe.

5. merge.renormalize is for known canonicalization transitions

If one history introduced different clean/smudge or text/eol/ident rules, current Git can virtually check out/check in all three merge stages before comparison. This can reduce conflicts caused by canonical-format changes rather than semantic edits.

git config --local merge.renormalize true

Use it only when the filters/attributes are understood and idempotent; it is not a generic line-ending conflict suppressor.

6. Stable text/binary attributes reduce platform-dependent surprises

* text=auto
*.sh text eol=lf
*.bat text eol=crlf
*.png binary

Separate broad normalization migrations from feature work. Otherwise a mechanical EOL change can alter rename similarity and conflict sets while obscuring meaningful edits.

7. The attribute chooses a driver name; configuration chooses executable behavior

generated/components.lock merge=generatedComponents
*.bin -merge
[merge "generatedComponents"]
    name = deterministic generated component merge
    driver = trusted-generated-merge %O %A %B %L %P

The built-in binary behavior keeps our tentative working-tree version but leaves the path conflicted. A custom driver must write its clean result into %A and return non-zero when it cannot decide safely.

8. Generated files usually belong to regeneration policy

If a generated file can be deterministically recreated from authoritative source manifests, merge those inputs and regenerate. A custom driver is justified only when the generated format has a precise, deterministic combination rule and regeneration is not the better control.

9. Lock files require ecosystem-specific semantics

A package-manager lock file is not ordinary prose. Some ecosystems expect regeneration after manifest integration; others preserve solver choices that require review. Generic ours, union, or concatenation policies can create a syntactically valid but impossible dependency state. Name the authoritative package tool and validation command.

10. The built-in union driver is narrow

append-only-unordered.txt merge=union

Union keeps lines from both sides, but current documentation warns the resulting order may be arbitrary. It is unsuitable for source code or ordered configuration unless the format genuinely treats lines as an unordered set.

11. Strategy and strategy-option selection are exceptional tools

Current ort enables rename detection and has options for rename thresholds, diff algorithms, whitespace, and renormalization. Change them because evidence shows the default model is wrong for a specific history—not because the conflict is inconvenient.

12. Custom drivers must declare runtime portability

  • POSIX shell may be available in Linux/macOS/Git Bash but not every Windows GUI or runner.
  • Python, Node.js, or PowerShell drivers need a compatible runtime version.
  • Local .git/config does not travel with clone.
  • Hosted merge buttons use server-controlled Git/config and may not run local drivers.
  • Filesystem case/file-mode/symlink behavior can change path-level conflicts.

13. Decision table

Scenario Preferred policy Fallback
Source code conflict ort + explicit resolution + tests abort/retry on integration branch
Repeated maintenance conflict rerere + validation forget obsolete resolution and re-resolve
Historical EOL/filter transition attributes + justified renormalize dedicated normalization migration
Generated artifact merge sources then regenerate narrow custom driver with fail-closed semantics
Non-mergeable binary explicit conflict/owner decision regenerate or choose authoritative artifact

14. Knowledge check

Question 1. Does zdiff3 change merge semantics?

Question 2. Why might rerere.autoUpdate remain false?

Question 3. When is merge.renormalize appropriate?

Question 4. Why does a tracked .gitattributes driver name not make CI ready?

Question 5. What is normally safer for generated artifacts?

15. Summary

Configuration is effective when it clarifies evidence or encodes a tested format rule. Conflict presentation, rerere, normalization, strategy options, and drivers should all preserve a clear validation boundary.

Next

Diagnose silent merge failures

Lesson 4 covers ours shortcuts, semantic breakage, obsolete rerere reuse, missing drivers, rename/normalization surprises, and version assumptions.

Authoritative references

 git-merge
 merge-strategies
 gitattributes
 git-rerere

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.