独立合并/相当于 git diff --no-index 的 3 路

问题描述 投票:0回答:2

我们可以使用

git
的 diff 工具,无需使用
git diff --no-index <FILE-A> <FILE-B>
的 git 存储库。

是否有类似的命令来运行

git
的合并算法,给定三个输入文件(“我们的”、基础和“他们的”)?具体来说,它应该输出“diff3”样式(看到冲突中的“base”至关重要)

我知道它不可能像 git 的递归合并策略那么智能,但我会对像“解决”策略这样的基本东西感到非常满意。

git command-line diff three-way-merge
2个回答
3
投票
git merge-file -p --diff3 ours base theirs

0
投票

运行 git 的合并算法

实际上有不止一种合并结果,具体取决于所使用的 diff 算法:myers、minimal、patience 和 histogram。
有关详细信息,请参阅 Lup Peng Loke 的“何时使用每种 Git Diff 算法”。

正如jthillanswer中提到的,您可以使用

git merge-file
:

在 Git 2.44(2024 年第 1 季度)中,“

git merge-file
(man) 学会了采用
--diff-algorithm
选项来使用与默认 myers diff 不同的算法。

请参阅commit 4f7fd79(2023 年 11 月 20 日),作者:Antonin Delpeuch (

wetneb
)
(由 Junio C Hamano --
gitster
--
合并于 commit 7895686,2023 年 12 月 18 日)

merge-file
:添加 --diff-algorithm 选项

签署人:Antonin Delpeuch
审阅者:Phillip Wood

在使用“

git merge-file
(man)命令时,可以使用“myers”默认算法之外的其他差异算法,通过选择更新的算法(例如“”)来帮助避免虚假冲突直方图”,例如使用“
git merge-file
”作为自定义合并驱动程序的一部分时。

git merge-file
现在包含在其 手册页中:

--diff-algorithm={patience|minimal|histogram|myers}

合并时使用不同的 diff 算法。当前默认值为“myers”, 但选择更新的算法(例如“直方图”)会有所帮助 避免由于不重要的匹配行而发生错误合并 (例如来自不同函数的大括号)。也可以看看

git diff
--diff-algorithm

所以现在:

git merge-file -p --diff-algorithm={patience|minimal|histogram|myers} --diff3 ours base theirs
© www.soinside.com 2019 - 2024. All rights reserved.