2

This question already has an answer here:

After executing these 4 commands, directory "a" has file "1" with contents "test" and file "2" which is empty, and directory "b" is empty.

$ mkdir a
$ mkdir b
$ echo test > a/1
$ touch a/2

We can run

$ diff -r a b
Only in a: 1
Only in a: 2

Which isn't helpful for a patch. Or, we can run

$ diff -rN a b
diff -rN a/1 b/1
1d0
< test

Which is great for file "1" because we see its contents, but now file "2" has disappeared. This is because the -N flag means "treat absent files as empty", so I presume diff can't see the difference between the empty file "a/2" and the (pretend, since really empty) empty file "b/2".

Is there a way to make diff show us, in one execution, that a new empty file has been created, and the contents of a new non-empty file -- in a format that patch can use?

Or, would this require a new option to diff?

marked as duplicate by Michael Durrant, Michael Homer, Ramesh, Stephen Kitt, Anthon Jun 18 '15 at 5:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    This question is clearly not a duplicate of the referenced question. The user explicitly tried what was proposed as a solution in the referenced question and that did not solve his problem. – Dubu Jun 18 '15 at 7:56
  • @Durrant and others - can you guys un-mark this as a duplicate? Dubu is correct. In fact, that post is where I read about the -N option. But, using that is where I ran into the unwanted side effect of -N making "b" basically disappear in the diff, where not using -N would at least tell you "b" only exists in one place. – user1902689 Jun 22 '15 at 19:30
0

Unfortunately the plain diff from GNU diffutils cannot handle changes such as b (remove empty files). makepatch might be useful for that situation. It's available as a package on Debian/Ubuntu.

Not the answer you're looking for? Browse other questions tagged or ask your own question.