[英]Annotated diff file with “<<<<<<< mine” and “>>>>>>> yours” type markers
I am trying to create a diff file using the Linux diff command that has markers like this (taken from diff3 man page): 我正在尝试使用具有以下标记的Linux diff命令创建一个diff文件(取自diff3手册页):
<<<<<<< mine
lines from mine
=======
lines from yours
>>>>>>> yours
This format is very intuitive for me and allows me to easily fix merge conflicts in vim and it works great when I am trying to merge three files (mine, yours and original) using diff3 but I would like the same format from plain diff. 这种格式对我来说非常直观,可以让我轻松地解决vim中的合并冲突,当我尝试使用diff3合并三个文件(mine,您的文件和原始文件)时,它的效果很好,但我希望使用普通diff的相同格式。 I was hoping this would be simple but I have not been able to get it.
我希望这会很简单,但我一直没能做到。 I have tried most of the main options (-e,--ed, etc.) and even tried to create a --changed-group-format but was unsuccessful.
我尝试了大多数主要选项(-e,-ed等),甚至尝试创建--changed-group-format,但未成功。
Hopefully this is something simple that I just overlooked. 希望这是我刚刚忽略的简单事情。
UPDATE: 更新:
Two file diff example with added line, removed line and conflict line: 两个文件差异示例,其中添加了行,删除了行和冲突行:
You could play with the diff options. 您可以使用diff选项。 The shell script below
下面的shell脚本
diff \
--unchanged-group-format='%=' \
--old-group-format='' \
--new-group-format='%>' \
--changed-group-format='<<<<<<< mine
%<=======
%>>>>>>>> yours
' \
orig.txt new.txt
Outputs 产出
This has some stuff
in that gets
modified in
a later version
<<<<<<< mine
and there is a conflict
=======
and there is a conflict (like here)
>>>>>>> yours
about which version
should be used.
newline
For the files as in your screenshot. 对于文件,如您的屏幕截图所示。 You could look more formatting options for the diff in a documentation, eg here .
您可以在文档中找到diff的更多格式选项,例如here 。
One liner (works from command line, at least on linux): 一种衬板(至少在Linux上可从命令行运行):
diff --unchanged-group-format="%=" --old-group-format="" --new-group-format="%>" --changed-group-format="<<<<<<< mine%c'\\12'%<=======%c'\\12'%>>>>>>>> yours%c'\\12'" orig.txt new.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.