Windows下使用Beyond Compare作為git的比對與合并工具

來源:互聯網
上載者:User

標籤:http   ar   os   使用   sp   java   檔案   on   問題   

Windows下使用Beyond Compare作為git的比對與合并工具 介紹

其實各種git的GUI用戶端都有內建比對工具,但是一開始學Git的時候,用的是Windows下的Git Bash,後來也漸漸熟悉各種命令,用圖形用戶端反而不習慣了。
這裡介紹如何將Beyond Compare配置為git的difftool和mergetool。當需要比對或者合并衝突時,就可以通過difftool和mergetool調用Beyond Compare進行比對和合并衝突了。

操作

目前我電腦裡安裝的是Beyond Compare 4,就介紹一下4的設定,Beyond Compare 3也是類似的。
其實Beyond Compare官網就有介紹
如何配置git的difftool和mergetool,其實就幾行git命令。

#difftool 配置git config --global diff.tool bc4git config --global difftool.bc4.cmd "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""#mergeftool 配置git config --global merge.tool bc4git 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看看配置情況,才發現原因。
開啟設定檔看到的資訊差不多是這樣:

[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檔案設定,就沒問題了。

.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

Windows下使用Beyond Compare作為git的比對與合并工具

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.