簡體中文 ▾ 主題 ▾ 最新版本 ▾ git-merge-index 最後更新於 2.35.0

名稱

git-merge-index - 對需要合併的檔案執行合併操作

概要

git merge-index [-o] [-q] <merge-program> (-a | ( [--] <file>…​) )

描述

此命令會在索引中查詢 <file>(s),如果存在任何合併條目,則將這些檔案的 SHA-1 雜湊值作為引數 1、2、3 (如果檔案不存在則為空引數) 傳遞,並將 <file> 作為引數 4 傳遞。這三個檔案的檔案模式作為引數 5、6 和 7 傳遞。

選項

--

不再將任何後續引數解釋為選項。

-a

對索引中所有需要合併的檔案執行合併。

-o

不停止於第一次失敗的合併,而是一次性完成所有合併 —— 即使之前的合併返回錯誤,也繼續進行合併,並在所有合併完成後才返回錯誤碼。

-q

不要抱怨合併程式失敗(合併程式失敗通常表示合併過程中存在衝突)。這適用於可能需要發出自定義訊息的“瓷器(porcelains)”介面。

如果 git merge-index 被呼叫時帶有多個 <file>s (或 -a),它會依次處理它們,僅當合並返回非零退出程式碼時才停止。

通常,這會透過一個指令碼執行,該指令碼呼叫 Git 對 RCS 包中 merge 命令的模擬。

發行版中包含一個名為 git merge-one-file 的示例指令碼。

警告!警告!警告!Git 的“合併物件順序”與 RCS merge 程式的合併物件順序不同。在上述排序中,原始檔案位於第一位。但三方合併程式 merge 的引數順序是讓原始檔案位於中間。別問我為什麼。

示例

torvalds@ppc970:~/merge-test> git merge-index cat MM
This is MM from the original tree.		# original
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.		# current contents

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] 套件的一部分

scroll-to-top