简体   繁体   English

只复制差异(kdiff,winmerge,任何差异工具)

[英]Copy only difference (kdiff, winmerge, any diff like tool)

Is there possibility of copy ONLY difference of two files? 是否有可能只复制两个文件的差异? Like in winmerge, but, I can't find this option 就像在winmerge,但是,我找不到这个选项 在此输入图像描述

Just like on this screen- i want to copy only 'yellow part' . 就像在这个屏幕上 - 我只想复制'黄色部分'。 Of course I can do that manually, but in big file it's not too funny :-) 当然我可以手动完成,但在大文件中它不是太有趣:-)

WinMerge has a built-in and simple way to generate such "diff only" files, that they called "patches". WinMerge有一种内置且简单的方法来生成这样的“diff only”文件,他们称之为“补丁”。

Click on "Tool", then on "Generate Patch...", and enter where you want to store the result: 单击“工具”,然后单击“生成修补程序...”,并输入要存储结果的位置:

在此输入图像描述

You will obtain (for your example) the file 您将获得(对于您的示例)文件

4,8c4,8
< HELLO WORLD
< HELLO WORLD
< HELLO WORLD
< HELLO WORLD
< HELLO WORLD
---
> 
> 
> 
> 
> 

That uses the standard, compact way of representing diff and is easy to manipulate. 它使用标准,紧凑的方式表示差异 ,易于操作。

There is a free app called DiffMerge . 有一个名为DiffMerge的免费应用程序。

Note : The option ' Show differences only ' will be disabled until you switch to the bottom tab labeled Referenced View(Files as loaded). 注意:在您切换到标记为Referenced View(文件已加载)的底部选项卡之前,将禁用“ 仅显示差异 ”选项。 After that you should be able to use Differences Only view. 之后,您应该能够使用“仅差异”视图。

与内容的差异

差别而已

Here is how you do it in WinMerge: 以下是WinMerge中的操作方法:

  1. Disable any context lines: [View] > [Context] > [0 Lines]. 禁用任何上下文行:[查看]> [上下文]> [0行]。
  2. Select pane of interest: Click on pane. 选择感兴趣的窗格:单击窗格。
  3. Select all text: [Edit] > [Select All] or [Ctrl]+[a]. 选择所有文本:[编辑]> [全选]或[Ctrl] + [a]。
  4. Copy selection: [Edit] > [Copy] or [Ctrl]+[c]. 复制选择:[编辑]> [复制]或[Ctrl] + [c]。

In winmerge there is very nice feature- in tools you can generate raport in html by Tools-> Raport. 在winmerge中,有一个非常好的功能 - 您可以通过Tools-> Raport在html中生成raport。 After that operation you can parse generated html- and in that way get only differenece (but maybe it's not simplest solution) 在那个操作之后你可以解析生成的html-并以这种方式获得只有差异(但也许这不是最简单的解决方案)

Most diff tools have a patch generation functionality which can work toward the clipboard, this is mostly what you want as you will get only changed text on left and right side (if you remove the context lines). 大多数diff工具都有一个补丁生成功能,它可以用于剪贴板,这主要是你想要的,因为你只会在左侧和右侧获得改变的文本(如果删除上下文行)。 If you want only those of one side you can easily filter the patch with regard to the first character (removing all lines, using an editor, matching something like ^[+>].*$ to keep removed lines or ^[-<].*$ to keep added lines). 如果你只想要一方的那些,你可以轻松过滤关于第一个字符的补丁(删除所有行,使用编辑器,匹配^[+>].*$以保留删除的行或^[-<].*$以保持添加的行)。

The diff tool in command line will output just that, piped with a grep and one of the above regular expression you are done. 命令行中的diff工具将输出,使用grep和上述正则表达式之一管道输出。

WinMerge提供“Copy Left to ...”或“Copy right to ...”,它只会将差异复制到所选的文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM