2011-09-21 77 views
6

有很多用於爲文本文件等創建文件級補丁的解決方案。我在尋找的是一個簡單的腳本/ shell命令,它將比較oldversion/newversion /併爲我提供一個需要在oldversion上進行復制以使其等同於newversion的文件樹(假設文件未在更新中刪除版)。請注意,這兩個文件夾都包含二進制文件和文本文件。用於創建文件/文件夾級補丁(包括二進制文件)的兩個目錄樹的差異

以前,我們使用了黑客:

fdupes -qrf newversion/ oldversion/ | grep "newversion" | xargs rm;

與文件夾「NEWVERSION」可能被打包成一個補丁離開我們。

不幸的是,事實證明這是災難性的,因爲fdupes不考慮文件名。

什麼是偉大的東西就像fdupes,實際上包括在比較中的文件名。

+0

你在尋找的只是「新」文件列表,而不是「修改」文件在newversion /? –

+0

新文件和修改後的文件。 –

回答

5

diff命令可以被要求而不同輸出的文件名。

diff --quiet --recurse --unidirectional-new-file OLDDIR NEWDIR 

Files old/main and new/main differ 
Files old/main.cpp and new/main.cpp differ 
Files old/Makefile and new/Makefile differ 
Files old/sounds/popalien.wav and new/sounds/popalien.wav differ 
Files old/sounds/saucer.wav and new/sounds/saucer.wav differ 

當然,這不是一個很好的輸出,但是,因爲你只在尋找新的文件打包爲一個補丁,快速SED管道工程奇蹟:

diff --quiet --recurse -unidirectional-new-file OLDDIR NEWDIR | \ 
    sed "s/^.* and \(.*\) differ/\1/" 

(打破了可讀性)圍繞 '和' 和前述

new/main 
new/main.cpp 
new/Makefile 
new/sounds/popalien.wav 
new/sounds/saucer.wav 

空間 '不同'

的操作數的順序差異有所不同,第一個論點是'和',第二個是在之後。小心那個。

此外,如果您從NEWDIR中刪除文件,則不會將其作爲給定的文件找到,只會添加或更改文件。還要輸出任何一個子目錄中找不到的文件的文件名,用--new-file替換--unidirection-new-file。 (除了 - 單向以外,所有的選項都是短的)

1

diff -ruN oldversion newversion

0

我知道它已經很久了。我需要同樣的解決方案我發現這篇文章,但它不夠。然後我發現rsync可以完成IFF的工作,你「補丁」相同的副本,並且不需要與其他更改合併。我打算在斷開的機器上使用它來更新yum鏡像。我的完整的解決方案是一個涉及多一點,而我從存儲器寫入命令,這樣一些細節可能是錯的,但在覈心:

# create identical copy "copy.0" 
rsync -a master/ copy.0/ 

# Presumably transfer copy.0/ to another machine for offline use 
# but copy.0 must not mutate outside of this process or sync probably 
# will not work. 

# some time later update master, e.g. rsync master from upstream mirror 
# mutates master in some way, changes/adds/removes remove files including 
# binaries 
echo -n $'\001\002' > master/new.bin 
rm master/gone.bin 

# generate rsync batch that can be used to ``patch`` copy.0 
# to become identical to master 
rsync -a --delete --itemize-changes --only-write-batch=copy.0.batch \ 
    master/ copy.0/ 
# now the file copy.0.batch contains only the deltas to be applied 

# transfer the batch file to where it needs to be applied 

# apply the batch to copy.0 
rsync -a --delete --itemize-changes --read-batch=copy.0.batch copy.0/ 

這需要照顧的缺失和許多其他的東西,可能權限,時間戳等,但我認爲它可能不會將硬鏈接視爲硬鏈接,並可能將它們創建爲單獨的未鏈接文件。

相關問題