我有兩個文字文件,除了幾行上的一些更改之外,它們幾乎相同。我想將這兩個文件合併到一個文字檔案中,並突出顯示差異,以便我可以在編輯器上查看合併的文件並手動查看這些差異。
我想,這有點類似於您通常從 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