0

If I want to get the difference between the 2 directories, I use the command below:

diff -aruN dir1/ dir2/ > dir.patch

so the dir.patch file should comprise all differences I want, right?

But if dir2/ contains a file with empty content, and that file is not existent in dir1/, for example,

dir1/

dir2/empty_content_file.txt ------ with empty content.

Then the diff command will not generate any patch for empty_content_file.txt, but it is a needed file.

Is there any expertise or alternative way to do this?

Thank you in advance.

2 Answers 2

1

It's because you're using -N option, which is added to explicitly treat absent file as empty. man diff says :

     -N,  --new-file 
              treat absent file as empty
Sign up to request clarification or add additional context in comments.

6 Comments

But the diff command never creates the patch without -N option for inexistent files in dir1/, so -N is necessary...
Well I've tested with or without -N option. Without -N option it does show the existence of a file.
No, no patch is generated without -N argument for inexistent files in the first directory, it shows "Only in dir2/: empty_content_file.txt".
I had uploaded the screenshot of the operations you mentioned.
Okay, I understand your point. You want new file to be added when applying the patch. I believe there's no better option than using git diff.
|
0

The screenshot below shows the operation of "diff -aru" command for inexistent files in the first directory, a message "Only in xxx" will show.

The diff command without -N option for inexistent files in the first directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.