Skip to content

Instantly share code, notes, and snippets.

@bobo52310
Created January 9, 2016 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobo52310/57db1af38cd87ddcd05a to your computer and use it in GitHub Desktop.
Save bobo52310/57db1af38cd87ddcd05a to your computer and use it in GitHub Desktop.
Terminal 環境下更好用的檔案比較差異工具(diff tools) 推薦使用 `icdiff` 這一套

Terminal 環境下更好用的檔案比較差異工具(diff tools)

推薦使用 icdiff 這一套:https://github.com/jeffkaufman/icdiff

用法:

如何比較兩個檔案差異:

$icdiff <file_1> <file_2>

備註:覺得好用的話,可以將內建的 diff 指令改用 icdiff。

如何搭配 git 使用:

$git difftool --extcmd icdiff

也可以有更精簡的 git 用法:

$git icdiff

只需要設定 git difftool path 指向 git-icdiff 檔案即可。

icdiff 設定為 git 預設比對差異工具:

已經習慣 git 預設的 git diff 指令了嗎?別擔心,我們可以設定 git 預設使用這一套來做差異比對,讓我們可以沿用原本熟悉的 git diff 指令,同時享用 icdiff 清楚的比對結果:

$git diff

該如何讓 git diff 預設使用 icdiff,設定方法如下:

  1. .gitconfig 設定

     [diff]
     	# 使用 icdiff 來取代 git 內建的 diff
         external = ~/bin/git-diff-wrapper.sh
    
  2. 建立 ~/bin/git-diff-wrapper.sh 檔案,加入以下內容:

     #!/bin/bash
     icdiff $2 $5
    

3.完成!趕緊來使用 $git diff 看看吧

參考資料:

@bobo52310
Copy link
Author

CentOS 上面安裝 icdiff 步驟:
pip install icdiff

touch /bin/git-diff-wrapper.sh
chmod 777 /bin/git-diff-wrapper.sh
vim /bin/git-diff-wrapper.sh
#!/bin/bash
icdiff $2 $5

touch ~/.gitconfig
vim ~/.gitconfig
[diff]
# 使用 icdiff 來取代 git 內建的 diff
external = /bin/git-diff-wrapper.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment