作为一种变通方法所做的修改,我目前运行rsync
两次浪费了大量的时间:
ORIG=/path/to/original
MOD=/path/to/modded
# find the modified/added files:
mkdir modded && rsync -axP --prune-empty-dirs --compare-dest=$ORIG $MOD/ modded
# the other way around, includes both deleted and modded files
mkdir deleted && rsync -axP --prune-empty-dirs --compare-dest=$MOD $ORIG/ deleted
# find the modded files and remove them
for i in $(find deleted); do [ -e modded${i#deleted} ] && rm $i; done
# delete the empty directories
find modded delete -type d -empty -delete
# create a list of the deleted files
cd deleted && find -type f > ../deleted.list && cd ..
# tar the modifications
cd modded && tar czf ../modded.tgz && cd ..
rm -rf deleted modded
现在modded.tgz
包含修改/添加的文件,而deleted.list
包含已删除文件的名称,因此应用它们运行
tar xf modded.tgz
while read -r line; do rm $line; done < deleted.list
这也有可能转换用于创建一个补丁文件,而不是...
有一点要注意:这个我绊倒了。 ORIG和MOD都需要是绝对路径。如果他们不是rsync会抛出一个找不到它的错误,但由于-P标志用于显示进度,因此它会很快隐藏在输出中。最终的结果是整个目录树被复制(因为它找不到原始文件),这绝对不是我们想要的结果,在我的情况下,因为我在区分文件系统,所以花了很长时间才完成。 – ecbtln
@ecbtln好点,我只用过这一次,没有想到更多关于它... –