← all lessons

foundation · 2026-08-21 · generated-filesgitgitattributeslockfilesmerge

The .gitattributes -merge attribute

The idea

.gitattributes can turn off the merge driver for a path with -merge. On a conflict, git then stops trying to interleave hunks. It keeps the current branch's whole version of the file and reports a plain conflict. This matters for generated files: a text merge can splice two halves into something that still parses but is wrong — a composer.lock with a content hash that matches nothing, and no warning. A loud conflict you regenerate from is safer than a quiet merge that lies about what's in the file.

How it shows up

composer.lock -merge
languages/**/*.mo binary
languages/**/*.l10n.php -merge
languages/**/*.json -merge

The right way to resolve these is always "rebuild" — composer install, or recompile the translations — never "pick hunks". binary on the .mo files is the stronger form: no line diff at all, so you pick a side and rebuild.

Read more

Exercises

  1. Mark a generated file -merge — add a line for a lockfile or build output to a repo's .gitattributes. Done when: git check-attr merge <file> prints merge: unset.
  2. Force a conflict and see the difference — branch, change the file on both sides, merge. Done when: git reports a conflict but the file holds only one side's content, not spliced hunks.

My notes