简体   繁体   English

使diff忽略符号链接

[英]make diff to ignore symbolic link

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. 当我使用diff创建补丁文件时,/ /project/config.mk已正确完成,但这两个符号链接出现了一些问题。 They were both treated as new files, the diff sections were the whole content of the config.mk file. 它们都被视为新文件,diff部分是config.mk文件的全部内容。 I tried to find a diff option to disable following symbolic link, but there is no such option available. 我试图找到一个diff选项来禁用跟随符号链接,但没有这样的选项可用。 Any suggestions are appreciated. 任何建议表示赞赏。

As Overbose's suggestion, I create this script. 作为Overbose的建议,我创建了这个脚本。 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

在GNU diff v3.3中,现在有一个选项--no-dereference可以解决问题

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

Use find in the following way: 使用find以下列方式:

find . ! -type l

This option should skip following symbolic links. 此选项应跳过以下符号链接。 Use that command to locate your file before running diff. 使用该命令在运行diff之前找到您的文件。

As a summary of what I did try. 作为我所做的总结尝试。 Working solution was to use the --no-dereference for my case. 工作解决方案是使用--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 对于-X选项,您可以获得以下链接的帮助: stackoverflow.com:how-do-you-diff-a-directory-for-only-files-of-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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM