1
diff -ur dir1 dir2 | diffstat

this is similar to git diff --stat, but diffstat is ignoring "Only in dir1" and "Only in dir2" files, whereas git diff adds it to deletion and insertion counts respectively. Is there a way to make diffstat to do the same?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
rodee
  • 3,233
  • 5
  • 34
  • 70

2 Answers2

0
diff -ur --exclude=".git" dir1/ dir2/ | grep -i "only in dir1" | awk '{print $3 $4}' | sed 's/\:/\//' | xargs cat | wc -l

I am adding this command's output with the deletions(-) count spit by the diffstat command in the question to get the actual deletions count, similarly for the insertions(+) count.

rodee
  • 3,233
  • 5
  • 34
  • 70
0

Simpler:

diff -urN dir1/ dir2/ |diffstat

using GNU diff's -N option, e.g., when comparing directories:

If only one file exists, diff normally does not show its contents; it merely reports that one file exists but the other does not. You can make diff act as though the missing file is empty, so that it outputs the entire contents of the file that actually exists. (It is output as either an insertion or a deletion, depending on whether the missing file is in the first or the second position.) To do this, use the --new-file (-N) option.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105