Chr*_*iss 6 linux directory patch compare
有很多解决方案可以为文本文件等创建文件级补丁.我正在寻找的是一个简单的脚本/ shell命令,它将比较oldversion/newversion /并给我一个文件树,我需要复制oldversion以使其等于newversion(假设文件未在更新中删除)版).请注意,这两个文件夹包含二进制文件和文本文件.
以前,我们使用的是hack:
fdupes -qrf newversion/ oldversion/ | grep "newversion" | xargs rm;
离开我们的文件夹"newversion",可以打包为补丁.
不幸的是,这被证明是灾难性的,因为fdupes不考虑文件名.
什么是伟大的是像fdupes,实际上包括比较中的文件名.
可以要求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
Run Code Online (Sandbox Code Playgroud)
当然,它不是一个很好的输出,但由于你只是寻找新文件打包作为补丁,快速sed管道工作奇迹:
diff --quiet --recurse -unidirectional-new-file OLDDIR NEWDIR | \
sed "s/^.* and \(.*\) differ/\1/"
Run Code Online (Sandbox Code Playgroud)
(为便于阅读而破损)
new/main
new/main.cpp
new/Makefile
new/sounds/popalien.wav
new/sounds/saucer.wav
Run Code Online (Sandbox Code Playgroud)
'和'周围的空格和'不同'之前的空格
diff的操作数的ORDER有所不同,第一个参数是'和',第二个是后.注意这一点.
此外,如果您从NEWDIR中删除文件,则不会找到它,只会添加或更改文件.要同时输出在subdir中找不到的文件的文件名,请将--unidirection-new-file替换为--new-file.(除了--unidirectional ..之外的所有短选项都存在.)