使用Beyond Compare进行svn diff

问题描述

最近发现了一款很好用的diffmerge的软件Beyond Compare。于是考虑是不是能够将这个软件使用在日常的文件对比和版本管理中。

问题解决

首先下载Beyond Compare的最新版本。安装好了之后安装命令行工具,执行Install Commond Line Tools。这样我们就可以使用bcompbcompare两个命令来进行文件对比了。

bcomp会打开app窗口并保持而不是立刻返回。bcompare会在打开窗口后立刻返回。所以这里我们使用bcomp命令。

~中新建一个脚本.BCDiff,脚本内容如下:

#!/bin/bash

DIFF="bcomp"

LEFT=${6}
RIGHT=${7}

$DIFF $LEFT $RIGHT
exit 0    # 这个返回0是为了防止上面的diff命令的返回值被svn diff接收到以为是出错

之后修改~/.subversion/config文件中的diff-cmd一行为diff-cmd = ~/.BCDiff即可。

此外注意自己写的那个脚本要添加运行权限。

chmod +x ./.BCDiff

相关原理

svn diff机制

svn diff为我们提供了一个使用自己的对比程序的机制。用在diff program位置的程序会接受一组形如

-u -L tag1 (revision 171313) -L tag2 (working copy) file1 file2

的参数。其中第六个第七个参数为对比的两个文件的绝对路径。因此我们可以利用一个脚本把这两个路径传递给需要的diff程序。这不仅适用与使用beyond compare,也适用于其他对比方式比如vimdiff

Beyond Compare机制

Beyond Compare的命令行形式bcomp使用方法如下:

Beyond Compare
Copyright (c) 1996-2016 Scooter Software.  All rights reserved.

Syntax:
  bcomp [options] [<Left> [<Right> [<Center> [<Output>]]]]
  bcomp @<ScriptFile> [options]

For more information on the options below check the help.

Options:
  -nobackups               Disables backup file creation
  -ro                      Disables editing on all sides
  -ro#                     Disables editing on specified side
  -title#=<title>          Shows description instead of filename in path edit
  -vcs#=<path>             Uses version control path instead of real filename
                             for file format matching, displayed in path
                             edits if -title isn't defined

File View Options:
  -fv[=<type>]             Opens new file view
  -qc[=<type>]             Silently compares two files
  -savetarget=<filename>   Saves to specified filename instead of original file

Folder View Options:
  -sync                    Opens new Folder Sync view

Merge Options:
  -automerge               Automatically merges files without interaction
  -favorleft, favorright   Suppresses output coloring for favored side
  -force                   Adds conflict markers to output if -automerge fails
  -iu                      Turns on "Ignore Unimportant Differences"
  -mergeoutput=<filename>  Specifies an output file
  -reviewconflicts         Opens interactive window if -automerge fails

Script Options:
  -closescript             Closes script window when finished
  -silent                  Runs script without showing window

A # character in a switch should be replaced by a side number:
  1=Left, 2=Right, 3=Center, 4=Output

Comparison result return values:
    0  Success
    1  Binary same
    2  Rules-based same
   11  Binary differences
   12  Similar
   13  Rules-based differences
   14  Conflicts detected
  100  Error
  101  Conflicts detected, merge output not saved
  102+ Error

我们一共可以传递四个文件路径参数进去。传递两个表示一左一右。三个表示一左一右还有一个中间的。四个表示一左一右一个中间的还有一个在下面是输出的文件路径。

这里我们传递两个参数进行对比。

但是要注意的是下面的返回值。默认情况使用会按照两个文件的对比情况返回对应的值。但是svn diff接受这些非零的值的时候会认为对比出现了问题从而终止整个程序。因此在上面的脚本中我们加上了exit 0用于返回一个成功给svn diff的外部程序。

综上,我们就可以使用Beyond Compare来进行svn diff对比文件了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • git和svn是目前最常用的团队协作的版本控制系统。 本人起初用过git,后来用过svn。算是两个版本控制系统都用...
    江湖相望知冷暖阅读 9,850评论 0 6
  • 命令的使用 1、检出 svn cohttp://路径(目录或文件的全路径)[本地目录全路径] --username...
    小李龍彪阅读 9,877评论 0 9
  • 源代码管理工具-SVN 一. 了解-源代码管理工具概述 1. 源代码管理工具的作用?> 能追踪一个项目从诞生一直到...
    Louis_hey阅读 13,933评论 1 8
  • 概述 本文主要为从代码层面分析 Containerd diff 服务模块的实现逻辑,如下图 containerd ...
    Xiao_Yang阅读 6,459评论 0 1
  • 职场中 有的人溜须拍马 有的人阿谀奉承 有的人欺上瞒下 有的人只手遮天 有的人装腔作势 有的人默默无闻 有的人无所...
    简得飞兔阅读 4,278评论 4 22