查看差异

One of the commonest requirements in project development is to see what has changed. You might want to look at the differences between two revisions of the same file, or the differences between two separate files. TortoiseSVN provides a built-in tool named TortoiseMerge for viewing differences of text files. For viewing differences of image files, TortoiseSVN also has a tool named TortoiseIDiff. Of course, you can use your own favourite diff program if you like.

文件差异

本地修改

如果你想看到你的本地副本有哪些更加,只用在资源管理器中右键菜单下选TortoiseSVN比较差异

与另外一个分支/标签之间的差异

如果你想查看主干程序(假如你在分支上开发)有哪些修改或者是某一分支(假如你在主干上开发)有哪些修改,你可以使用右键菜单。在你点击文件的同时按住Shift键,然后选择TortoiseSVN URL比较。在弹出的对话框中,将特别显示将与你本地版本做比较的版本的URL地址。

你还可以使用版本库浏览器,选择两个目录树比较,也许是两个标记,或者是分支/标记和最新版本。邮件菜单允许你使用比较版本来比较它们。阅读“比较文件夹”一节以便获得更多信息。

与历史版本的比较差异

如果你想查看某一特定版本与本地副本之间的差异,使用显示日志对话框,选择要比较的版本,然后选择在右键菜单中选与本地副本比较差异

If you want to see the difference between the last committed revision and your working copy, assuming that the working copy hasn't been modified, just right click on the file. Then select TortoiseSVNDiff with previous version. This will perform a diff between the revision before the last-commit-date (as recorded in your working copy) and the working BASE. This shows you the last change made to that file to bring it to the state you now see in your working copy. It will not show changes newer than your working copy.

两个历史版本的比较

如果你要查看任意已提交的两个历史版本之间的差异,在版本日志对话框中选择你要比较的两个版本(一般使用 Ctrl-更改),然后在右键菜单中选比较版本差异

如果你在文件夹的版本日志中这样做,就会出现一个比较版本对话框,显示此文件夹的文件修改列表。阅读“比较文件夹”一节以便获得更多信息。

提交所有修改

如果你要在一个视窗中查看某一版本的所有更改,你可以使用统一显示所有比较 (GNU 片段整理)。它将显示所有修改中的部分内容。它很难显示一个全面清晰的比较,但是会将所有更改都集中显示出来。在版本日志对话框中选择某一版本,然后在右键菜单中选择统一显示所有比较

文件差异

如果你要查看两个不同文件之间的差异,你可以直接在资源管理器中选择这两个文件(一般使用 Ctrl-modifier),然后右键菜单中选TortoiseSVN比较差异

WC文件/文件夹与URL之间的比较差异

If you want to see the differences between a file in your working copy, and a file in any Subversion repository, you can do that directly in explorer by selecting the file then holding down the Shift key whilst right clicking to obtain the context menu. Select TortoiseSVNDiff with URL. You can do the same thing for a working copy folder. TortoiseMerge shows these differences in the same way as it shows a patch file - a list of changed files which you can view one at a time.

追溯信息之间的比较差异

如果你要查看的不仅是比较差异而且包括修改该版本的作者,版本号和日期,你可以在版本日志对话框中综合比较差异和谴责信息。这里有更多详细介绍“追溯不同点”一节

比较文件夹差异

TortoiseSVN 自带的内置工具不支持查看多级目录之间的差异,但你可以使用支持该功能的外置工具来替代。在 “其他的比较/合并工具”一节 介绍了一些我们使用过的工具。

If you have configured a third party diff tool, you can use Shift when selecting the Diff command to use the alternate tool. Read “外部程序设置”一节 to find out about configuring other diff tools.

行结束符和空白选项

Sometimes in the life of a project you might change the line endings from CRLF to LF, or you may change the indentation of a section. Unfortunately this will mark a large number of lines as changed, even though there is no change to the meaning of the code. The options here will help to manage these changes when it comes to comparing and applying differences. You will see these settings in the Merge and Blame dialogs, as well as in the settings for TortoiseMerge.

忽略行结束符排除仅行结束符的差异。

比较空白将所有缩进和行内空白差异视为增加/删除的行。

Ignore whitespace changes excludes changes which are due solely to a change in the amount or type of whitespace, eg. changing the indentation or changing tabs to spaces. Adding whitespace where there was none before, or removing a whitespace completely is still shown as a change.

忽略所有空白排除仅空白改变的差异。

自然的,任何已经修改内容的行永远都包含在差异中。

比较文件夹

图 5.23. 修订版本版本比较对话框

修订版本版本比较对话框


当你在版本库浏览器中选择了两个树,或者在日志对话框中选择了一个文件夹的两个版本,就可以使用上下文菜单比较版本

这个对话框显示一个所有已经修改的文件列表,允许你使用邮件菜单单独的比较或回溯它们。

你也可以将已经修改的文件列表导出到一个文本文件中,或者将修改的文件导出到一个目录。这个操作只在选择的文件上工作,所以你需要选择感兴趣的文件 - 通常是所有文件。

If you want to export the list of files and the actions (modified, added, deleted) as well, you can do that using the keyboard shortcuts Ctrl-A to select all entries and Ctrl-C to copy the detailed list to the clipboard.

顶部的按钮允许你改变比较的方向。你可以显示从A到B的修改,或者如果你喜欢,显示从B到A的修改。

有版本数字的按钮可以用来改变版本范围。当你改变范围时,两个版本不同的项目列表会自动更新。

If the list of filenames is very long, you can use the search box to reduce the list to filenames containing specific text. Note that a simple text search is used, so if you want to restrict the list to C source files you should enter .c rather than *.c.

使用 TortoiseIDiff 进行比较的图像

我们有许多有用的比较文本文件的工具,包括我们自带的TortoiseMerge,但是我们也需要查看图像文件的更改。这就是我们设计TortoiseIDiff的原因。

图 5.24. 差异察看器截图

差异察看器截图


TortoiseSVN比较差异 会启动 TortoiseIDiff 显示常用格式的图像差异。一般情况下是左右对称地显示两个图像,但你也可以通过视图菜单或者工具栏切换为上下显示的模式,或者如果你愿意,也可以重叠显示图像。

Naturally you can also zoom in and out and pan around the image. You can also pan the image simply by left-dragging it. If you select the Link images together option, then the pan controls (scrollbars, mousewheel) on both images are linked.

An image info box shows details about the image file, such as the size in pixels, resolution and colour depth. If this box gets in the way, use ViewImage Info to hide it. You can get the same information in a tooltip if you hover the mouse over the image title bar.

When the images are overlaid, the relative intensity of the images (alpha blend) is controlled by a slider control at the left side. You can click anywhere in the slider to set the blend directly, or you can drag the slider to change the blend interactively. Ctrl+Shift-Wheel to change the blend.

滑杆上部的按钮在两个混合展现之间切换,它标记了混合滑杆控制哪边。默认一个在顶部,另一个在底部,所以切换按钮只是在一个图像与另一个之间转换。你可以移动标记选择切换按钮使用哪个混合值。

Sometimes you want to see a difference rather than a blend. You might have the image files for two revisions of a printed circuit board and want to see which tracks have changed. If you disable alpha blend mode, the difference will be shown as an XOR of the pixel colour values. Unchanged areas will be plain white and changes will be coloured.

其他的比较/合并工具

如果我们提供的这些工具不是你所需要的,可以尝试使用一些其他开源的或者商业的软件。每个人都有不同喜好,下面列表虽不完全,或许有些你也会认可的:

WinMerge

WinMergeWinMerge也是一款很好的能处理目录的开源软件。

Perforce Merge

Perforce 是一款商业 RCS,但是你也可以免费下载到。可以从Perforce获得更多信息。

KDiff3

KDiff3也是一款能处理目录的免费比较工具。你可以从here下载。

ExamDiff

ExamDiff Standard是免费软件。它能处理文件但不能处理目录。ExamDiff Pro是共享软件,拥有一系列的功能包括目录比较和编辑的能力。对于以上体验,3.2及以上版本能处理二进制。你可以从PrestoSoft下载它们。

Beyond Compare

和ExamDiff Pro一样,这也是一款很不错的共享软件,同样也能进行目录比较和二进制处理。下载地址Scooter Software

Araxis Merge

Araxis Merge is a useful commercial tool for diff and merging both files and folders. It does three-way comparison in merges and has synchronization links to use if you've changed the order of functions. Download it from Araxis.

SciTE

这款文本编译器在统一比较时提供语法显示,读起来更加容易。可以从这里下载Scintilla

Notepad2

Notepad2的设计旨在替代 Windows自带的记事本的功能,它以开源编译控制为基础。在查看统一比较时,它能实现比Windows自带的记事本更多功能。免费下载here

“外部程序设置”一节这里可以了解到怎样起用TortoiseSVN来使用这些工具。