8 月 132008
 

Freehaha’s notes: diff && patch

diff 跟patch 真是很好用的工具

diff 是用來比較兩個檔案的
當你要比較新舊的code 差在哪裡, 可以這樣寫 (diff old.file new.file)

# diff db.c db1.c
416c416
< sky =” SKY_CLOUDY;”> else if ( weather_info.mmhg <= 1320 ) weather_info.sk— db.c 2007-05-19

當然如果你不喜歡這種寫法, 通常比較多人會用 diff -u
這樣看起來更清爽
# 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
# patch < patching file db.c

這樣就把 db.c 更新了!
————-
當然diff, patch 沒那麼笨, 一次只能一個檔案

# diff -ruN src/ src.new/ > src.diff
# cd src && patch < src.diff

這樣就可以一次就patch 完囉!

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

CAPTCHA Image
Play CAPTCHA Audio
Reload Image