合併兩個文字文件,突出顯示差異

合併兩個文字文件,突出顯示差異

我有兩個文字文件,除了幾行上的一些更改之外,它們幾乎相同。我想將這兩個文件合併到一個文字檔案中,並突出顯示差異,以便我可以在編輯器上查看合併的文件並手動查看這些差異。

我想,這有點類似於您通常從 svn 合併衝突中得到的結果。例如file1包含:

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
Salami
Mortadella
Prosciutto
Creole Mustard
Bottom piece of bread

file2包含:

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
Sauerkraut
Grilled Chicken
Creole Mustard
Bottom piece of bread

我希望合併的文件包含類似以下內容:

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
<<<<<<< .file1
Salami
Mortadella
Prosciutto
=======
Sauerkraut
Grilled Chicken
>>>>>>> .file2
Creole Mustard
Bottom piece of bread

也許diff我缺少一個選項?

答案1

最終版本,新增了 OP--changed-group-format

diff old-file new-file --old-group-format='<<<<<<< .old
%<=======
' --new-group-format='=======
%>>>>>>>> .new
' --changed-group-format='<<<<<<< .old
%<=======
%>>>>>>>> .new
'

這導致

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
<<<<<< .old
Salami
Mortadella
Prosciutto
=====
Sauerkraut
Grilled Chicken
>>>>>>> .new
Creole Mustard
Bottom piece of bread

答案2

您在尋找嗎?您可以使用 WinMerge 或超編輯為了這..

相關內容