diff 是用來比較兩個檔案的
當你要比較新舊的code 差在哪裡, 可以這樣寫 (diff old.file new.file)
# diff db.c db1.c當然如果你不喜歡這種寫法, 通常比較多人會用 diff -u
416c416
< sky =" SKY_CLOUDY;"> else if ( weather_info.mmhg <= 1320 ) weather_info.sk--- db.c 2007-05-19
這樣看起來更清爽
# diff -u db.c db1.c
--- db.c 2007-05-19 14:19:12.000000000 +0800--------------
+++ db1.c 2007-05-27 14:43:17.000000000 +0800
@@ -413,7 +413,7 @@
if ( weather_info.mmhg <= 980 ) weather_info.sky = SKY_LIGHTNING; else if ( weather_info.mmhg <= 1000 ) weather_info.sky = SKY_RAINING; - else if ( weather_info.mmhg <= 1020 ) weather_info.sky = SKY_CLOUDY; + else if ( weather_info.mmhg <= 1320 ) weather_info.sky = SKY_CLOUDY; else weather_info.sky = SKY_CLOUDLESS; }
patch 是diff 的好兄弟
patch 可以用 diff 輸出的檔案來update 舊的檔案
# diff -u db.c db1.c > db.c.diff這樣就把 db.c 更新了!
# patch ;lgt
patching file db.c
-------------
當然diff, patch 沒那麼笨, 一次只能一個檔案
# diff -ruN src/ src.new/ > src.diff
# cd src && patch < src.diff
這樣就可以一次就patch 完囉!