Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make diff to ignore symbolic link

Tags:

linux

diff

patch

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
like image 221
Dien Nguyen Avatar asked Mar 28 '11 08:03

Dien Nguyen


People also ask

How do I dereference a symbolic link?

To dereference a symbolic link means to follow the link to the target file rather than work with the link itself. When you dereference a symbolic link, you end up with a pointer to the file (the filename of the target file). The term no-dereference is a double negative: It means reference.

Does git ignore symbolic links?

Git does not follow symbolic links when accessing a . gitignore file in the working tree. This keeps behavior consistent when the file is accessed from the index or a tree versus from the filesystem.

Does RM remove symbolic links?

Using the rm Command We know the rm command can delete files and directories. Additionally, we can use this command to delete symbolic links. As the output above shows, We have successfully deleted fileLink. The syntaxes of deleting a symbolic link and a file are the same.

Do symbolic links have their own inode?

A symbolic link has its own inode number. When you create a symbolic link, you create a new physical file with its own inode number, as shown in Figure 1. Because a symbolic link refers to a file by its path name rather than by its inode number, a symbolic link can refer to files in other mounted file systems.


1 Answers

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

like image 90
Bernd Gloss Avatar answered Oct 10 '22 07:10

Bernd Gloss