git-merge-tree
Combine and analyze content differences between trees
SYNOPSIS
git-merge-tree [--write-tree | --name-only]
PARAMETERS
The common ancestor tree ID or reference.
The 'our' side tree ID or reference.
The 'their' side tree ID or reference.
--write-tree
Write the merged tree to the object database and print its ID. This is the default behavior if conflicts are resolved.
--name-only
List paths of modified or conflicting files instead of writing a tree. It does not resolve conflicts; it reports them by name.
DESCRIPTION
git-merge-tree is a plumbing command used to perform a three-way merge between two tree-ish objects, given a common base tree-ish. It computes the object ID of the resulting merged tree or lists affected paths. This command is typically not used directly by end-users but serves as a low-level building block for higher-level merge commands like git-merge-recursive. It takes the object IDs of the base, local, and remote trees as arguments. The merge process considers entries at the same path from all three trees and produces a combined tree. If conflicts occur for a given path, special conflict markers are typically placed, or the conflicted path is omitted if the --name-only option is used. The command effectively simulates a merge without updating the working directory, making it useful for scripting and internal Git operations that need to compute a merged tree state.
CAVEATS
This is a plumbing command, primarily for internal Git use or scripting, not for direct end-user interaction.
It only merges trees, not working directories. It computes the resulting tree object but does not modify files in the working directory or update the index.
It does not automatically resolve all conflicts. Conflicted paths might be omitted or marked depending on options and internal logic.
PURPOSE AS A PLUMBING COMMAND
git-merge-tree is a "plumbing" command, which means it's designed to be used as a building block for higher-level "porcelain" commands or scripts. It operates on fundamental Git objects (trees) and provides raw output, making it suitable for automated processes rather than direct interactive use by end-users.
OUTPUT FORMAT
By default, git-merge-tree outputs the object ID of the newly created merged tree. If the --name-only option is used, it instead outputs a list of paths that are modified or conflict, indicating which files would be affected by the merge.
THREE-WAY MERGE LOGIC
The command performs a three-way merge by comparing the local and remote trees against their base common ancestor. It identifies changes unique to local, changes unique to remote, and common changes. It then combines these changes, resolving non-conflicting differences automatically.
HISTORY
git-merge-tree has been part of Git's core plumbing commands for a long time, serving as a fundamental component for its three-way merge capabilities. Its design reflects Git's philosophy of providing low-level, composable tools. It's often called internally by higher-level merge strategies to compute the merged state of different branches. Its primary purpose has remained consistent: to perform the core logic of a three-way tree merge, abstracting away the details of file-level content merging.
SEE ALSO
git-merge(1), git-merge-recursive(1), git-merge-one-file(1), git-read-tree(1), git-write-tree(1)