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_fi开发者_C百科le}
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
In GNU diff v3.3 there is now an option --no-dereference that does the trick
If you add lines like:
dir1/config.mk
dir2/config.mk
to a file .ignore-diff
then you can execute diff(1)
like this:
diff -ur -X .ignore-diff
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.
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
# 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
精彩评论