Skip to content

git-merge-index

为需要合并的文件运行合并。

概要

txt
'git merge-index' [-o] [-q] <merge-program> (-a | ( [--] <file>...) )

描述

此命令在索引中查找 <file>,如果有任何合并条目,则将这些文件的 SHA-1 哈希作为参数 1、2、3(如果没有文件则为空参数)传递,<file> 作为参数 4。三个文件的文件模式作为参数 5、6 和 7 传递。

选项

--

:不再将后续参数解释为选项。

-a

:对索引中所有需要合并的文件运行合并。

-o

:不要在第一次合并失败时停止,而是一次性完成所有合并——即使之前的合并返回错误也继续合并,只在所有合并完成后返回错误代码。

-q

:不要抱怨合并程序失败(合并程序失败通常表示合并过程中存在冲突)。这是为可能想要发出自定义消息的 porcelain 命令准备的。 如果使用多个 <file>(或 -a)调用 git merge-index,它会依次处理它们,只有在合并返回非零退出码时才停止。

通常这是通过调用 Git 模仿 RCS 包中 'merge' 命令的脚本来运行的。

发行版中包含一个名为 'git merge-one-file' 的示例脚本。

注意注意注意!Git 的 "merge object order" 与 RCS 'merge' 程序的合并对象顺序不同。在上述排序中,原始文件排在第一位。但三方合并程序 'merge' 的参数顺序是将原始文件放在中间。不要问为什么。

示例:

torvalds@ppc970:~/merge-test> git merge-index cat MM
This is MM from the original tree.		# 原始文件
This is modified MM in the branch A.		# merge1
This is modified MM in the branch B.		# merge2
This is modified MM in the branch B.		# 当前内容

或者

torvalds@ppc970:~/merge-test> git merge-index cat AA MM
cat: : No such file or directory
This is added AA in the branch A.
This is added AA in the branch B.
This is added AA in the branch B.
fatal: merge program failed

后一个示例展示了 'git merge-index' 一旦有任何返回错误就会停止合并(即 cat 对 AA 文件返回了错误,因为它在原始文件中不存在,因此 'git merge-index' 甚至没有尝试合并 MM 文件)。

Git

git(1) 套件的一部分

基于 CC BY-NC-SA 3.0 许可发布