{
    "mode": "man",
    "parameter": "git-merge-tree",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/git-merge-tree/1/json",
    "generated": "2026-08-30T03:00:52Z",
    "synopsis": "git merge-tree [--write-tree] [<options>] <branch1> <branch2>\ngit merge-tree [--trivial-merge] <base-tree> <branch1> <branch2> (deprecated)",
    "sections": {
        "NAME": {
            "content": "git-merge-tree - Perform merge without touching index or working tree\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git merge-tree [--write-tree] [<options>] <branch1> <branch2>\ngit merge-tree [--trivial-merge] <base-tree> <branch1> <branch2> (deprecated)\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This command has a modern --write-tree mode and a deprecated --trivial-merge mode. With the\nexception of the DEPRECATED DESCRIPTION section at the end, the rest of this documentation\ndescribes the modern --write-tree mode.\n\nPerforms a merge, but does not make any new commits and does not read from or write to either\nthe working tree or index.\n\nThe performed merge will use the same features as the \"real\" git-merge(1), including:\n\n•   three way content merges of individual files\n\n•   rename detection\n\n•   proper directory/file conflict handling\n\n•   recursive ancestor consolidation (i.e. when there is more than one merge base, creating a\nvirtual merge base by merging the merge bases)\n\n•   etc.\n\nAfter the merge completes, a new toplevel tree object is created. See OUTPUT below for\ndetails.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-z",
                    "content": "Do not quote filenames in the <Conflicted file info> section, and end each filename with\na NUL character rather than newline. Also begin the messages section with a NUL character\ninstead of a newline. See the section called “OUTPUT” below for more information.\n",
                    "flag": "-z"
                },
                {
                    "name": "--name-only",
                    "content": "In the Conflicted file info section, instead of writing a list of (mode, oid, stage,\npath) tuples to output for conflicted files, just provide a list of filenames with\nconflicts (and do not list filenames multiple times if they have multiple conflicting\nstages).\n\n--[no-]messages\nWrite any informational messages such as \"Auto-merging <path>\" or CONFLICT notices to the\nend of stdout. If unspecified, the default is to include these messages if there are\nmerge conflicts, and to omit them otherwise.\n",
                    "long": "--name-only"
                },
                {
                    "name": "--allow-unrelated-histories",
                    "content": "merge-tree will by default error out if the two branches specified share no common\nhistory. This flag can be given to override that check and make the merge proceed anyway.\n\n--merge-base=<commit>\nInstead of finding the merge-bases for <branch1> and <branch2>, specify a merge-base for\nthe merge, and specifying multiple bases is currently not supported. This option is\nincompatible with --stdin.\n",
                    "long": "--allow-unrelated-histories"
                }
            ]
        },
        "OUTPUT": {
            "content": "For a successful merge, the output from git-merge-tree is simply one line:\n\n<OID of toplevel tree>\n\nWhereas for a conflicted merge, the output is by default of the form:\n\n<OID of toplevel tree>\n<Conflicted file info>\n<Informational messages>\n\nThese are discussed individually below.\n\nHowever, there is an exception. If --stdin is passed, then there is an extra section at the\nbeginning, a NUL character at the end, and then all the sections repeat for each line of\ninput. Thus, if the first merge is conflicted and the second is clean, the output would be of\nthe form:\n\n<Merge status>\n<OID of toplevel tree>\n<Conflicted file info>\n<Informational messages>\nNUL\n<Merge status>\n<OID of toplevel tree>\nNUL\n",
            "subsections": [
                {
                    "name": "Merge status",
                    "content": "This is an integer status followed by a NUL character. The integer status is:\n\n0: merge had conflicts\n1: merge was clean\n<0: something prevented the merge from running (e.g. access to repository\nobjects denied by filesystem)\n"
                },
                {
                    "name": "OID of toplevel tree",
                    "content": "This is a tree object that represents what would be checked out in the working tree at the\nend of git merge. If there were conflicts, then files within this tree may have embedded\nconflict markers. This section is always followed by a newline (or NUL if -z is passed).\n"
                },
                {
                    "name": "Conflicted file info",
                    "content": "This is a sequence of lines with the format\n\n<mode> <object> <stage> <filename>\n\nThe filename will be quoted as explained for the configuration variable core.quotePath (see\ngit-config(1)). However, if the --name-only option is passed, the mode, object, and stage\nwill be omitted. If -z is passed, the \"lines\" are terminated by a NUL character instead of a\nnewline character.\n"
                },
                {
                    "name": "Informational messages",
                    "content": "This section provides informational messages, typically about conflicts. The format of the\nsection varies significantly depending on whether -z is passed.\n\nIf -z is passed:\n\nThe output format is zero or more conflict informational records, each of the form:\n\n<list-of-paths><conflict-type>NUL<conflict-message>NUL\n\nwhere <list-of-paths> is of the form\n\n<number-of-paths>NUL<path1>NUL<path2>NUL...<pathN>NUL\n\nand includes paths (or branch names) affected by the conflict or informational message in\n<conflict-message>. Also, <conflict-type> is a stable string explaining the type of conflict,\nsuch as\n\n•   \"Auto-merging\"\n\n•   \"CONFLICT (rename/delete)\"\n\n•   \"CONFLICT (submodule lacks merge base)\"\n\n•   \"CONFLICT (binary)\"\n\nand <conflict-message> is a more detailed message about the conflict which often (but not\nalways) embeds the <stable-short-type-description> within it. These strings may change in\nfuture Git versions. Some examples:\n\n•   \"Auto-merging <file>\"\n\n•   \"CONFLICT (rename/delete): <oldfile> renamed...but deleted in...\"\n\n•   \"Failed to merge submodule <submodule> (no merge base)\"\n\n•   \"Warning: cannot merge binary files: <filename>\"\n\nIf -z is NOT passed:\n\nThis section starts with a blank line to separate it from the previous sections, and then\nonly contains the <conflict-message> information from the previous section (separated by\nnewlines). These are non-stable strings that should not be parsed by scripts, and are just\nmeant for human consumption. Also, note that while <conflict-message> strings usually do not\ncontain embedded newlines, they sometimes do. (However, the free-form messages will never\nhave an embedded NUL character). So, the entire block of information is meant for human\nreaders as an agglomeration of all conflict messages.\n"
                }
            ]
        },
        "EXIT STATUS": {
            "content": "For a successful, non-conflicted merge, the exit status is 0. When the merge has conflicts,\nthe exit status is 1. If the merge is not able to complete (or start) due to some kind of\nerror, the exit status is something other than 0 or 1 (and the output is unspecified). When\n--stdin is passed, the return status is 0 for both successful and conflicted merges, and\nsomething other than 0 or 1 if it cannot complete all the requested merges.\n",
            "subsections": []
        },
        "USAGE NOTES": {
            "content": "This command is intended as low-level plumbing, similar to git-hash-object(1), git-mktree(1),\ngit-commit-tree(1), git-write-tree(1), git-update-ref(1), and git-mktag(1). Thus, it can be\nused as a part of a series of steps such as:\n\nNEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)\ntest $? -eq 0 || die \"There were conflicts...\"\nNEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)\ngit update-ref $BRANCH1 $NEWCOMMIT\n\nNote that when the exit status is non-zero, NEWTREE in this sequence will contain a lot more\noutput than just a tree.\n\nFor conflicts, the output includes the same information that you’d get with git-merge(1):\n\n•   what would be written to the working tree (the OID of toplevel tree)\n\n•   the higher order stages that would be written to the index (the Conflicted file info)\n\n•   any messages that would have been printed to stdout (the Informational messages)\n",
            "subsections": []
        },
        "INPUT FORMAT": {
            "content": "git merge-tree --stdin input format is fully text based. Each line has this format:\n\n[<base-commit> -- ]<branch1> <branch2>\n\nIf one line is separated by --, the string before the separator is used for specifying a\nmerge-base for the merge and the string after the separator describes the branches to be\nmerged.\n",
            "subsections": []
        },
        "MISTAKES TO AVOID": {
            "content": "Do NOT look through the resulting toplevel tree to try to find which files conflict; parse\nthe Conflicted file info section instead. Not only would parsing an entire tree be\nhorrendously slow in large repositories, there are numerous types of conflicts not\nrepresentable by conflict markers (modify/delete, mode conflict, binary file changed on both\nsides, file/directory conflicts, various rename conflict permutations, etc.)\n\nDo NOT interpret an empty Conflicted file info list as a clean merge; check the exit status.\nA merge can have conflicts without having individual files conflict (there are a few types of\ndirectory rename conflicts that fall into this category, and others might also be added in\nthe future).\n\nDo NOT attempt to guess or make the user guess the conflict types from the Conflicted file\ninfo list. The information there is insufficient to do so. For example: Rename/rename(1to2)\nconflicts (both sides renamed the same file differently) will result in three different files\nhaving higher order stages (but each only has one higher order stage), with no way (short of\nthe Informational messages section) to determine which three files are related.\nFile/directory conflicts also result in a file with exactly one higher order stage.\nPossibly-involved-in-directory-rename conflicts (when \"merge.directoryRenames\" is unset or\nset to \"conflicts\") also result in a file with exactly one higher order stage. In all cases,\nthe Informational messages section has the necessary info, though it is not designed to be\nmachine parseable.\n\nDo NOT assume that each path from Conflicted file info, and the logical conflicts in the\nInformational messages have a one-to-one mapping, nor that there is a one-to-many mapping,\nnor a many-to-one mapping. Many-to-many mappings exist, meaning that each path can have many\nlogical conflict types in a single merge, and each logical conflict type can affect many\npaths.\n\nDo NOT assume all filenames listed in the Informational messages section had conflicts.\nMessages can be included for files that have no conflicts, such as \"Auto-merging <file>\".\n\nAVOID taking the OIDS from the Conflicted file info and re-merging them to present the\nconflicts to the user. This will lose information. Instead, look up the version of the file\nfound within the OID of toplevel tree and show that instead. In particular, the latter will\nhave conflict markers annotated with the original branch/commit being merged and, if renames\nwere involved, the original filename. While you could include the original branch/commit in\nthe conflict marker annotations when re-merging, the original filename is not available from\nthe Conflicted file info and thus you would be losing information that might help the user\nresolve the conflict.\n",
            "subsections": []
        },
        "DEPRECATED DESCRIPTION": {
            "content": "Per the DESCRIPTION and unlike the rest of this documentation, this section describes the\ndeprecated --trivial-merge mode.\n\nOther than the optional --trivial-merge, this mode accepts no options.\n\nThis mode reads three tree-ish, and outputs trivial merge results and conflicting stages to\nthe standard output in a semi-diff format. Since this was designed for higher level scripts\nto consume and merge the results back into the index, it omits entries that match <branch1>.\nThe result of this second form is similar to what three-way git read-tree -m does, but\ninstead of storing the results in the index, the command outputs the entries to the standard\noutput.\n\nThis form not only has limited applicability (a trivial merge cannot handle content merges of\nindividual files, rename detection, proper directory/file conflict handling, etc.), the\noutput format is also difficult to work with, and it will generally be less performant than\nthe first form even on successful merges (especially if working in large repositories).\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\nGit 2.43.0                                   07/02/2025                            GIT-MERGE-TREE(1)",
            "subsections": []
        }
    },
    "summary": "git-merge-tree - Perform merge without touching index or working tree",
    "flags": [
        {
            "flag": "-z",
            "long": null,
            "arg": null,
            "description": "Do not quote filenames in the <Conflicted file info> section, and end each filename with a NUL character rather than newline. Also begin the messages section with a NUL character instead of a newline. See the section called “OUTPUT” below for more information."
        },
        {
            "flag": "",
            "long": "--name-only",
            "arg": null,
            "description": "In the Conflicted file info section, instead of writing a list of (mode, oid, stage, path) tuples to output for conflicted files, just provide a list of filenames with conflicts (and do not list filenames multiple times if they have multiple conflicting stages). --[no-]messages Write any informational messages such as \"Auto-merging <path>\" or CONFLICT notices to the end of stdout. If unspecified, the default is to include these messages if there are merge conflicts, and to omit them otherwise."
        },
        {
            "flag": "",
            "long": "--allow-unrelated-histories",
            "arg": null,
            "description": "merge-tree will by default error out if the two branches specified share no common history. This flag can be given to override that check and make the merge proceed anyway. --merge-base=<commit> Instead of finding the merge-bases for <branch1> and <branch2>, specify a merge-base for the merge, and specifying multiple bases is currently not supported. This option is incompatible with --stdin."
        }
    ],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Merge branches without changing files.",
        "examples": [
            {
                "description": "Show the result of a merge between two branches",
                "command": "git merge-tree {{branch1}} {{branch2}}"
            },
            {
                "description": "Perform a merge and write the resulting tree",
                "command": "git merge-tree --write-tree {{branch1}} {{branch2}}"
            }
        ]
    }
}