##介紹 其實各類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