git-merge-driver
БесплатноБез исполняемых скриптовНе проверенWrite a custom git merge driver that merges a file's structure instead of its lines. Use when a tool-rewritten JSON/YAML/lock file keeps conflicting on…
от laurigates★ 61 звезда на GitHubОб этом скилле
Custom Git Merge Drivers
A merge driver is a program git runs to merge one file in place of its line-by-line merge. Git hands it the ancestor, our side and their side; it writes the result and reports whether the merge was clean. It is the right tool when a file conflicts on changes that carry no real disagreement: a timestamp two tool runs both rewrote, a counter, registry entries each branch added at the same spot.
When to Use This Skill
| Use this skill when... | Use something else when... |
|---|---|
| A tool-rewritten structured file (JSON/YAML manifest, registry, generated index) conflicts on every parallel branch | The file is append-only with one entry per line → built-in merge=union (configure-plugin:configure-gitattributes) |
| The conflicts are mechanical: timestamps, counters, disjoint additions | A conflict is in front of you right now → resolve it; a driver only helps the next merge |
| You can state, field by field, what the right merge is | The file is regenerated from sources → regenerate it after merging instead |
Try the built-ins first. merge=union keeps both sides' lines with no
markers, merge=binary (or -merge) refuses to merge and keeps ours. A custom
driver is a program you now maintain, and it is the only option when the
correct merge depends on the file's structure.
How git calls a driver
A driver has two halves, and only one of them is committed:
| Half | Where | Committed? |
|---|---|---|
| Which files use it | .gitattributes: path/to/file.json merge=my-driver |
yes |
| What it runs | git config: merge.my-driver.driver = <command> |
no |
git config merge.my-driver.name "structural merge for file.json"
git config merge.my-driver.driver "python3 tools/merge.py %O %A %B %P"
| Placeholder | Meaning |
|---|---|
%O |
temp file: common ancestor (empty when both sides added the file) |
%A |
temp file: our side; write the merged result here |
%B |
temp file: their side |
%P |
the path being merged (for messages) |
%L |
conflict-marker size |
%S %X %Y |
conflict labels for ancestor, ours, theirs |
The contract (man gitattributes, "Defining a custom merge driver"):
| Exit code | Git's reading |
|---|---|
0 |
clean; %A is the result |
1–128 |
conflict; %A, whatever is in it, becomes the conflicted file |
> 128 |
the driver crashed; the whole merge fails instead of conflicting |
merge.<name>.recursive names the driver for the internal merge of several
merge bases; unset, the same driver runs there too.
Git runs drivers wherever it performs the merge itself: git merge, rebase,
cherry-pick, revert and stash pop/apply. GitHub's server-side
mergeability check and merge button do not, so a PR whose only conflict a
driver would resolve still shows as conflicting. Merge the base into the branch
locally and push (.claude/rules/gitattributes.md in claude-plugins records
this for merge=union; custom drivers behave the same).
Design rules for a structural driver
- Merge three ways, recursively. For each key: equal on both sides, take it; changed on one side only, take that change; added on one side, keep it; deleted on one side and untouched on the other, drop it. This alone resolves most "both branches touched the file" conflicts.
- Write field policies only for fields you can justify. "The later of two timestamps", "the larger of two counters", "the union of two lists that both only appended". Every policy is a claim that the field carries no real disagreement. Make it only where that is true.
- Keep related fields together. When fields describe one event (a run's time, result and stats), take all of them from one side. Merged field by field, the file can claim a time from one run and a result from the other.
- Everything else is a conflict. Two branches giving one id to two different records is exactly what a merge must surface. A driver that "resolves" it has hidden a bug.
- On conflict, write git's own markers. Run
git merge-file -L ours -L base -L theirs %A %O %Binto%Aand exit non-zero. The user then sees an ordinary conflict, not a half-merged file. If the line merge happens to come out clean, check that the result still parses before exiting 0. - Never exit above 128. Clamp the exit code. Git reads a crash code as "abort the merge", which is worse than a conflict.
- Fall back on unparseable input. If any side does not parse, line-merge as in rule 5 instead of raising.
- Preserve formatting byte for byte. Write the output with the same serializer settings the tool uses (indent, key order, trailing newline, non-ASCII escaping). Verify by round-tripping the committed file: parse and re-serialize must produce identical bytes, or every merge adds a diff.
- Know which interpreter git will run. A bare
python3in the driver command resolves through the PATH gi
Установить git-merge-driver в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Bash(git config --get *)Bash(git check-attr *)Bash(git merge *)Bash(git merge-file *)ReadWriteEditGrepGlobTodoWriteВложенные файлы
FAQ
Что делает скилл git-merge-driver?
Write a custom git merge driver that merges a file's structure instead of its lines. Use when a tool-rewritten JSON/YAML/lock file keeps conflicting on mechanical fields.
Как установить скилл git-merge-driver?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл git-merge-driver запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic