make diff 忽略符号链接
我的项目具有以下结构
/project/config.mk
/project/dir1/config.mk -> ../config.mk
/project/dir2/config.mk -> ../config.mk
当我使用 diff
创建补丁文件时,/project/config.mk
已正确完成,但两个符号链接出现了一些问题。它们都被视为新文件,差异部分是 config.mk 文件的全部内容。我试图找到一个 diff
选项来禁用以下符号链接,但没有这样的选项可用。任何建议表示赞赏。
根据 Overbose 的建议,我创建了这个脚本。有用。感谢大家抽出时间回答。
#!/bin/sh -v
ori_dir=$1
new_dir=$2
patch_file=./patch_file
if [ -f ${patch_file} ]
then
rm ${patch_file}
fi
ori_files=`cd ${ori_dir} ; find ./ -type f ! -type l`
for i in ${ori_files} ; do
if [ -f ${ori_dir}/$i ]
then
if [ -f ${new_dir}/$i ]
then
diff -rup ${ori_dir}/$i ${new_dir}/$i >> ${patch_file}
fi
fi
done
My project has the following structure
/project/config.mk
/project/dir1/config.mk -> ../config.mk
/project/dir2/config.mk -> ../config.mk
When I used diff
to create the patch file, the /project/config.mk
was done correctly, but the two symbolic links got some problems. They were both treated as new files, the diff sections were the whole content of the config.mk
file. I tried to find a diff
option to disable following symbolic link, but there is no such option available. Any suggestions are appreciated.
As Overbose's suggestion, I create this script. It works. Thank everyone for taking time answering.
#!/bin/sh -v
ori_dir=$1
new_dir=$2
patch_file=./patch_file
if [ -f ${patch_file} ]
then
rm ${patch_file}
fi
ori_files=`cd ${ori_dir} ; find ./ -type f ! -type l`
for i in ${ori_files} ; do
if [ -f ${ori_dir}/$i ]
then
if [ -f ${new_dir}/$i ]
then
diff -rup ${ori_dir}/$i ${new_dir}/$i >> ${patch_file}
fi
fi
done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 GNU diff v3.3 中,现在有一个选项 --no-dereference 可以解决这个问题
In GNU diff v3.3 there is now an option --no-dereference that does the trick
如果将如下行添加
到文件
.ignore-diff
中,则可以像这样执行
diff(1)
:If you add lines like:
to a file
.ignore-diff
then you can execute
diff(1)
like this:按以下方式使用 find:
此选项应跳过以下符号链接。在运行 diff 之前使用该命令找到您的文件。
Use find in the following way:
This option should skip following symbolic links. Use that command to locate your file before running diff.
作为我所做尝试的总结。工作解决方案是对我的案例使用 --no-dereference 。
对于 -X 选项,您可以通过此链接获取帮助:stackoverflow.com : 如何区分特定类型的仅文件目录
As a summary of what I did try. Working solution was to use the --no-dereference for my case.
for the -X option, you can get help with this link : stackoverflow.com : how-do-you-diff-a-directory-for-only-files-of-a-specific-type