← 返回命令列表

Linux command

git-merge-tree 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Preview merge result

git merge-tree [branch1] [branch2]

Perform a three-way merge

git merge-tree [base] [branch1] [branch2]

Check for merge conflicts and show informational messages

git merge-tree --write-tree --messages [branch1] [branch2]

Check if a branch can be cleanly merged

git merge-tree --write-tree --no-messages [branch1] [branch2]

说明

git merge-tree performs a three-way merge without touching the index or working tree. It shows what a merge would produce, making it useful for previewing merges or performing scripted merge analysis. The modern mode (default since Git 2.38) automatically finds the merge base, writes a result tree object, and reports conflicts. The exit code indicates success (0) or conflicts (1). This makes it ideal for CI pipelines and automation scripts that need to check mergeability without modifying any files. The deprecated trivial-merge mode requires specifying the base commit explicitly and only handles trivial merges.

参数

--write-tree
Modern mode (default since Git 2.38): automatically finds the merge base and writes a result tree object. Reports conflicts via exit code and stdout.
--trivial-merge
Deprecated mode: reads three trees and outputs trivial merge results. Requires explicit base.
--no-messages
Write informational messages such as "Auto-merging" and CONFLICT notices. Default: included when conflicts exist.
--name-only
In the output, show only filenames instead of full merge details.
--allow-unrelated-histories
Allow merging branches that share no common history.
--merge-base _commit_
Specify a merge base instead of computing one automatically. With this option, branch arguments can be trees instead of commits. Incompatible with --stdin.
--stdin
Read commits to merge from standard input, one pair per line. Implies -z.
-z
Use NUL characters as line terminators instead of newlines (for scripting).

FAQ

What is the git-merge-tree command used for?

git merge-tree performs a three-way merge without touching the index or working tree. It shows what a merge would produce, making it useful for previewing merges or performing scripted merge analysis. The modern mode (default since Git 2.38) automatically finds the merge base, writes a result tree object, and reports conflicts. The exit code indicates success (0) or conflicts (1). This makes it ideal for CI pipelines and automation scripts that need to check mergeability without modifying any files. The deprecated trivial-merge mode requires specifying the base commit explicitly and only handles trivial merges.

How do I run a basic git-merge-tree example?

Run `git merge-tree [branch1] [branch2]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --write-tree do in git-merge-tree?

Modern mode (default since Git 2.38): automatically finds the merge base and writes a result tree object. Reports conflicts via exit code and stdout.