1. 程式人生 > >ubuntu下git使用Beyond Compare來做diff和merge方法

ubuntu下git使用Beyond Compare來做diff和merge方法

    之前我寫過一篇文章, git使用vimdiff來做diff比較的 ,原文連結:

    有興趣的可以看一下。

    有時候檔案改動太多的時候, 使用vimdiff就不太方便了, 這裡建議使用Beyond Compare來做比較,相信熟悉windows開發的應該對這個工具都不陌生,非常好用的一款工具,話不多說,先到官網下載一個linux版本的工具:

    我的是ubuntu 64bit的, 那麼這裡就下載一個deb版本的 ,下載下來後bcompare-4.2.8.23479_amd64.deb。 

    雙擊安裝即可。

    安裝完成後就會在/usr/bin/下面找到bcompare 這個可執行檔案, 在終端上輸入bcompare,就可以啟動Beyond Compare了。

    接著配置git的global引數 :

git  config  --global   diff.tool bc3
git  config  --global   difftool.prompt false
git  config  --global   difftool.bc3.cmd '/usr/bin/bcompare "$LOCAL" "$REMOTE"'
git  config  --global   merge.tool bc3
git  config  --global   mergetool.prompt false
git  config  --global   mergetool.bc3.cmd '/usr/bin/bcompare "$LOCAL" "$REMOTE" "-savetarget=$MERGED"'
git  config  --global   mergetool.bc3.trustexitcode true
git  config  --global   alias.d  difftool
git  config  --global   alias.m  mergetool

    命令執行結束後,在使用者目錄下, cat  .gitconfig , 就可以看到以下內容:

[diff]
	tool = bc3
[difftool]
	prompt = false
[difftool "bc3"]
	cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\"
[merge]
	tool = bc3
[mergetool]
	prompt = false
[mergetool "bc3"]
	cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\" \"-savetarget=$MERGED\"
	trustexitcode = true
[alias]
	d = difftool
	m = mergetool

    正常使用的時候, 使用  git   d 或者 git  m 即可實現diff和merge的功能, 具體效果請自行體驗, 哈哈 !!