代码比较合并工具DiffMerge
10/21
本文最后更新于
2023年10月21日,已超过
497天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
笔者之前工作中主要使用商业版本的代码版本管理软件Perforce,它提供的p4v图形界面软件在diff&merge时很好用。后面要切换到Git版本管理软件,希望能有替代的图形工具能够实现diff&merge功能。在网上找了几款免费开源软件,但在内部HPC平台安装出现了问题(主要是图形依赖库问题),只有DiffMerge这款软件成功运行。So,就使用这款软件了。
介绍
DiffMerge是免费跨平台(Windows、OS X、Linux)的文件比较/合并工具。
功能:
- Diff功能,高亮显示两个文件差异
- 合并功能,可以显示三个文件差异(包括base版本),允许自动合并和手动合并
- 目录差异比较
软件下载地址:https://sourcegear.com/diffmerge/downloads.html
服务器操作系统是64位的Red Hat 7.4 (Maipo)
安装
下载RPM软件包为:diffmerge-4.2.0.697.stable-1.x86_64.rpm
- root用户安装
> rpm -ivh diffmerge-4.2.0.697.stable-1.x86_64.rpm
- 非root用户安装
$ rpm2cpio diffmerge-4.2.0.697.stable-1.x86_64.rpm | cpio -idvm
$ mv usr ~/apps/diffmerge
$ vim ~/.bashrc
export PATH=~/apps/diffmerge/bin:$PATH
$ source ~/.bashrc
使用
- 比较两个文件
$ diffmerge a.f90 b.f90
- 比较两个目录
$ diffmerge dir1 dir2
也可以在diffmerge界面中指定两个目录。
Git + DiffMerge组合
参考ToddHuss博客设置。
配置
在终端上执行以下命令:
$ git config --global diff.tool diffmerge
$ git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'
$ git config --global merge.tool diffmerge
$ git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
$ git config --global mergetool.diffmerge.trustExitCode true
以上命令设置内容对应~/.gitconfig
配置文件中设置:
[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\";
fi)\" \"$REMOTE\""
trustExitCode = true
使用
比较文件差异
# diff the local file.m against the checked-in version
git difftool file.m
# diff the local file.m against the version in some-feature-branch
git difftool some-feature-branch file.m
# diff the file.m from the Build-54 tag to the Build-55 tag
git difftool Build-54..Build-55 file.m
解决合并冲突
git mergetool
参考资料
https://twobitlabs.com/2011/08/install-diffmerge-git-mac-os-x/

