Progress:
TIER 2 · MODULE 53· Intermediate

git merge-one-file

What .gitattributes merge=union etc. dispatches to.

🎯 What & why

Internal three-way merge driver invoked per-file. This is what merge=union and friends in .gitattributes dispatch to, called by git merge-index once for every conflicted path.

🧠 Mental model

Plumbing-level, single-file merge: given three blob/mode/SHA triples (base, ours, theirs) and a path, write the merged result into the working tree and stage it (or report a conflict).

🛠️ Synopsis

git merge-one-file <orig-blob> <our-blob> <their-blob> <path> <orig-mode> <our-mode> <their-mode>

# Actually invoked indirectly:
git merge-index git-merge-one-file -a
git merge-index -o git-merge-one-file <paths>...

🎚️ Switches & options

FlagWhat it does
(positional) orig-blobSHA of the common ancestor blob, or empty string if absent
(positional) our-blobSHA of HEAD's version of the blob
(positional) their-blobSHA of MERGE_HEAD's version
(positional) pathWorking-tree path to write the merged result to
(positional) modesThree octal mode strings (orig, our, their); blank means missing

💡 Use cases

🧪 Examples

Re-run the merge driver for everything still conflicted
git merge-index -o git-merge-one-file -a
Drive merges only for two specific paths
git merge-index -o git-merge-one-file src/a.c src/b.c
Register a custom union-style driver in config
git config merge.ourunion.driver 'cat %A %B > %A'
Activate it for a path via gitattributes
echo 'CHANGELOG merge=ourunion' >> .gitattributes

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.