make diff 忽略符号链接

发布于 2024-10-27 09:06:02 字数 832 浏览 5 评论 0原文

我的项目具有以下结构

/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ぃ双果 2024-11-03 09:06:02

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

In GNU diff v3.3 there is now an option --no-dereference that does the trick

ら栖息 2024-11-03 09:06:02

如果将如下行添加

dir1/config.mk
dir2/config.mk

到文件 .ignore-diff

,则可以像这样执行 diff(1)

diff -ur -X .ignore-diff

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
兔小萌 2024-11-03 09:06:02

按以下方式使用 find:

find . ! -type l

此选项应跳过以下符号链接。在运行 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.

混浊又暗下来 2024-11-03 09:06:02

作为我所做尝试的总结。工作解决方案是对我的案例使用 --no-dereference 。

对于 -X 选项,您可以通过此链接获取帮助:stackoverflow.com : 如何区分特定类型的仅文件目录

# 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文