日常開發當中,團隊協作就要涉及到代碼版本的管理,代碼版本不斷的變化,項目合並時通常會比較同一代碼不同版本之間具體發生了哪些變化?還有常在shell終端開發下的我們對比文件我們又通常會用到一些對比的命令,無論是Linux的對比命令還是代碼版本管理的對比,輸出的對比文本大都比較樸素,如果差異小還好,如果差異大簡直要崩潰,剛好看到一個小工具,也從網上查了些相關資料,覺的是一個實用的小工具,在此分享給大家。
colordiff 是perl 開發一款小工具,與diff 功能一樣,但其擁有漂亮的語法和高亮差異顯示。小巧輕便又可以定制顏色方案。colordiff 適用於 Linux 及 BSD 系統,目前已被包含到 Debian、Ubuntu、Gentoo、Arch Linux、Fedora、FreeBSD 等發行版中。—— 【官方網站】
以下簡單針對幾個系統做下介紹:
Mac 系統
安裝方式
brew install colordiff
Ubuntu
apt-get install colordiff
CentOS
yum install colordiff
或者手動安裝,因軟件本身很小巧,安裝也很簡單,將下載到的源碼包解壓後,直接進行目錄中執行”make install”即可,程序和配置文件分別默認安裝在/usr/local/bin和/etc目錄下
wget http://www.colordiff.org/colordiff-1.0.16.tar.gz
tar -zxvf colordiff-1.0.16.tar.gz
cd colordiff-1.0.16
make install
ColorDiff 不同場景下的運用
colordiff file1 file2
diff -u file1 file2 | colordiff
如果需要修改顏色:sudo vim /usr/local/etc/colordiffrc
[helpers]
49 ### Set editor-cmd to the command used to invoke your text editor.
50 ### This will override the environment variables that Subversion
51 ### examines by default to find this information ($EDITOR,
52 ### et al).
53 # editor-cmd = editor (vi, emacs, notepad, etc.)
54 ### Set diff-cmd to the absolute path of your 'diff' program.
55 ### This will override the compile-time default, which is to use
56 ### Subversion's internal diff implementation.
57 # diff-cmd = diff_program (diff, gdiff, etc.)
58 ### Set diff3-cmd to the absolute path of your 'diff3' program.
59 ### This will override the compile-time default, which is to use
60 ### Subversion's internal diff3 implementation.
61 # diff3-cmd = diff3_program (diff3, gdiff3, etc.)
62 ### Set diff3-has-program-arg to 'yes' if your 'diff3' program
63 ### accepts the '--diff-program' option.
64 # diff3-has-program-arg = [yes | no]
65 ### Set merge-tool-cmd to the command used to invoke your external
66 ### merging tool of choice. Subversion will pass 4 arguments to
67 ### the specified command: base theirs mine merged
68 # merge-tool-cmd = merge_command
69 diff-cmd = colordiff
70 ### Section for configuring tunnel agents.