两个目录树的差异以创建文件/文件夹级别补丁(包括二进制文件)
有很多解决方案可以为文本文件等创建文件级补丁。我正在寻找的是一个简单的脚本/shell 命令,它将比较旧版本/新版本/,并给我一个文件树,我需要复制旧版本以使其等于新版本(假设更新后的文件中没有删除文件)版本)。请注意,这两个文件夹同时包含二进制文件和文本文件。
之前,我们使用了 hack:
fdupes -qrf newversion/ oldversion/ | grep "新版本" | xargs rm;
留给我们可以打包为补丁的文件夹“newversion”。
不幸的是,这结果是灾难性的,因为 fdupes 不考虑文件名。
最好的是像 fdupes 这样的东西,它实际上在比较中包含了文件名。
There's lots of solutions for creating a file level patch for text files and the like. What I'm looking for is an easy script/shell command that will compare oldversion/ newversion/ and give me a tree of files that I need to copy over oldversion to make it be equal to newversion (assuming files are not removed in the updated version). Note that the two folders contain both binary and text files.
Previously, we were using the hack:
fdupes -qrf newversion/ oldversion/ | grep "newversion" | xargs rm;
Leaving us with the folder "newversion" that could be packaged as a patch.
Unfortunately, this turned out to be disastrous because fdupes does not consider filenames.
What'd be great is something like fdupes that actually did include the filename in the comparison.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以要求 diff 命令输出不同的文件名。
当然,这不是一个很好的输出,但是由于您只是在寻找要打包为补丁的新文件,因此快速 sed 管道会产生奇迹:(
为了可读性而中断)
“and”周围的空格以及前面的“differ”
的顺序diff 的操作数有所不同,第一个参数是 ' 和 ' 的左边,第二个参数是之后。小心这一点。
另外,如果您从 NEWDIR 中删除文件,则不会找到给定的文件,而只会找到添加或更改的文件。要同时输出在任一子目录中找不到的文件的文件名,请将 --unidirection-new-file 替换为 --new-file。 (除了 --unidirection 之外,所有选项都存在短选项..)
The diff command can be asked to output filenames which differ.
Of course, it's not a nice output, but since you're only looking for NEW files to package as a patch, a quick sed pipe works wonders:
(broken for readability)
Spaces around 'and' and preceeding 'differ'
The ORDER of the operands to diff makes a difference, first argument is left of ' and ', second is after. Watch out for that.
Also, if you delete a file from NEWDIR, this will not find it as given, only added or changed files. To also output filenames for files not found in either subdir, replace the --unidirection-new-file with --new-file. (short options exist for all except --unidirectional..)
diff -ruN 旧版本新版本
diff -ruN oldversion newversion
我知道已经很久了。我需要相同的解决方案。我找到了这篇文章,但还不够。然后我发现 rsync 可以完成这项工作,只要你“修补”相同的副本,并且不需要与其他更改合并。我打算使用它来更新断开连接的机器上的 yum 镜像。我的完整解决方案涉及更多一些,我正在从内存中编写命令,因此一些细节可能是错误的,但核心是:
这负责删除和许多其他事情,可能权限、时间戳等等,但我认为它可能不会将硬链接处理为硬链接,并且可能会将它们创建为单独的未链接文件。
I know it has been long time. I needed same solution. I found this post but it was not sufficient. Then I found
rsync
can do the job IFF you ``patch`` identical copies, and don't need merging with other changes. I intend on using this with updating yum mirrors on disconnected machines. My full solution is a little more involved, and I am writing commands from memory so some fine details could be wrong, but at the core:This takes care of deletions and many other things, probably permissions, timestamps etc, but I think it might not handle hard links as hard link and will probably create them as separate unlinked files.