Hello,
The manual describes -S option as "start with FILE when comparing directories".
My intuition is that this should behave like -O option in git-diff [1]: show
differences in FILE first, then show differences in all other files. However,
it appears that diff behaves in a different (and quite weird) way: it first
composes an ordered list of files to compare, then cuts off the beginning of
this list until FILE, and only then starts comparing the remaining files. This
is extremely unintuitive and I consider this a bug (and if happens to be "by
design", then I propose a new feature request for -O option 🙂)
Specific example:
Create file structure as below, all files in the directory "one" should have
word "one" as the contents, all files in the directory "two" should word "two"
as the contents (so all files are different).
❯ tree -a
.
├── one
│ ├── dir
│ │ └── file
│ ├── .hidden-dir
│ │ └── file
│ ├── .hidden-file
│ └── zfile
└── two
├── dir
│ └── file
├── .hidden-dir
│ └── file
├── .hidden-file
└── zfile
6 directories, 8 files
❯ diff -ur one two | grep '+++' | wc -l
4
❯ diff -ur -S zfile one two | grep '+++' | wc -l
1
❯ diff -ur -S zfile one two
diff --color --unified -ur -S zfile one/zfile two/zfile
--- one/zfile 2018-05-24 01:23:49.237899164 +0200
+++ two/zfile 2018-05-24 01:24:58.260920662 +0200
@@ -1 +1 @@
-one
+two
I expect both diff calls to output differences in 4 files, only the second call
to print differences in the file "zfile" first.
[1]: https://git-scm.com/docs/git-diff#git-diff--Oltorderfilegt
Regards,
Maxim Baz