Diff
從差異重建文件
假設我有一個文件
foo
和一個文件bar
。我現在呼叫以下命令:$ diff foo bar > diff_foobar $ rm bar
是否有一種(n 簡單)的方法來以程式方式重建缺失
bar
的foo
和diff_foobar
?
是的,您應用了更新檔:
你做了:
$ diff foo bar > diff_foobar $ rm bar
現在做:
$ patch foo -o bar < diff_foobar
從差異重建文件,也稱為“應用差異”,是實用程序
patch
所做的:## Create two arbitrary files, `original' and `altered': $ seq 0 3 >original $ seq 7 11 >altered ## Compute a diff from `original' to `altered': $ diff original altered >diff ## Copy `original' before patching it $ cp -vi original original.0 `original' -> `original.0' $ patch <diff original # This modifies `original'! patching file original ## Confirm that we rebuilt the file from `original' and `diff` $ diff --report-identical-files original altered Files original and altered are identical
patch 命令也有很多選項,特別是反向應用更新檔。