##介绍 其实各类git的GUI客户端都有自带比对工具,可是一开始学Git的时候,用的是Windows下的Git Bash,后来也渐渐熟悉各类命令,用图形客户端反而不习惯了。 这里介绍如何将Beyond Compare配置为git的difftool和mergetool。当须要比对或者合并冲突时,就能够经过difftool和mergetool调用Beyond Compare进行比对和合并冲突了。php
##操做 目前我电脑里安装的是Beyond Compare 4,就介绍一下4的设置,Beyond Compare 3也是相似的。
其实Beyond Compare官网就有介绍 如何配置git的difftool和mergetool,其实就几行git命令。git
#difftool 配置 git config --global diff.tool bc4 git config --global difftool.bc4.cmd "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"" #mergeftool 配置 git config --global merge.tool bc4 git config --global mergetool.bc4.cmd "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"" git config --global mergetool.bc4.trustExitCode true
可是我照着上面的步骤配置,使用difftool命令后,发现左右两边都为空白文件。研究了半天没研究出个因此然。 后来忽然想起来用户目录下的.gitconfig看看配置状况,才发现缘由。 打开配置文件看到的信息差很少是这样:windows
[diff] tool = bc4 [difftool] prompt = false [difftool "bc4"] cmd = \"c:/program files (x86)/beyond compare 4/bcomp.exe\" .....
使用git bash是执行上述几个命令后,.gitconfig文件中并无 \"$LOCAL\" \"$REMOTE\""
的影子,因此使用difftool比对文件时,两边都是空白,由于根本就没有传参数进去。 因此换一个思路,不用命令设置,而是直接编辑.gitconfig文件设置,就没问题了。bash
.gitconfig文件新增以下配置并保存工具
[diff] tool = bc4 [difftool] prompt = false [difftool "bc4"] cmd = "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"" [merge] tool = bc [mergetool] prompt = false [mergetool "bc4"] cmd = "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
而后在git命令行中执行相关命令就ok啦:)命令行
#比对当前文件相对于Head版本的改动 git difftool <file_name> #当merge <branch_name>提示冲突时,执行下面命令即可以调出bc合并冲突 git mergetool