Linux make diff 忽略符号链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5456355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
make diff to ignore symbolic link
提问by Dien Nguyen
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.
我diff
以前创建补丁文件的时候/project/config.mk
是正确完成的,但是两个符号链接出现了一些问题。它们都被视为新文件,差异部分是config.mk
文件的全部内容。我试图找到一个diff
选项来禁用以下符号链接,但没有这样的选项可用。任何建议表示赞赏。
As Overbose's suggestion, I create this script. It works. Thank everyone for taking time answering.
根据 Overbose 的建议,我创建了这个脚本。有用。感谢大家花时间回答。
#!/bin/sh -v
ori_dir=
new_dir=
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
采纳答案by Heisenbug
Use find in the following way:
按以下方式使用查找:
find . ! -type l
This option should skip following symbolic links. Use that command to locate your file before running diff.
此选项应跳过以下符号链接。在运行 diff 之前使用该命令来定位您的文件。
回答by sarnold
If you add lines like:
如果添加如下行:
dir1/config.mk
dir2/config.mk
to a file .ignore-diff
到一个文件 .ignore-diff
then you can execute diff(1)
like this:
然后你可以这样执行diff(1)
:
diff -ur -X .ignore-diff
回答by Bernd Gloss
In GNU diff v3.3 there is now an option --no-dereference that does the trick
在 GNU diff v3.3 中,现在有一个选项 --no-dereference 可以解决这个问题
回答by Micka?l
As a summary of what I did try. Working solution was to use the --no-dereference for my case.
作为我所做尝试的总结。工作解决方案是对我的情况使用 --no-dereference 。
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
对于 -X 选项,您可以通过以下链接获得帮助:stackoverflow.com : how-do-you-diff-a-directory-for-only-files-of-a-specific-type
# max diff
diff -ruN ~/xxx-web/ ~/www/xxx/xxx-web/ > ~/xxx-web/20180523-diff.patch
# but may get too much symbolic link following, so in GNU diff v3.3 use :
diff --no-dereference -ruN ~/xxx-web/ ~/www/xxx/xxx-web/ > ~/xxx-web/20180523-diff.patch
## if no options available, you can try a solution that do not seem to work under 3.3 :
# find . -type l > .diffignore
## passing direct file will not work, it require file pattern ?
# diff -ruN -x .diffignore
## passing with xargs do not seem to work the way below on 3.3 ...
# diff -ruN $(cat .diffignore | xargs -L1 echo "-x ")
# diff -ruN $(cat .diffignore | xargs -i echo "-x '{}'" | sed 's,\./vivaoresto-web/,*,g') \
# inFolder outFolder > diff.patch
# if you wanna apply your path in the source directory :
cd ~/www/xxx/xxx-web/
patch -p1 < ~/xxx-web/20180523-diff.patch