如何使 diffstat 计数已删除和新添加的文件到 LOC 计数?

How to make diffstat count removed and newly added files to LOC count?

diff -ur dir1 dir2 | diffstat

这类似于 git diff --stat,但 diffstat 忽略 "Only in dir1" 和 "Only in dir2" 文件,而 git diff 分别将其添加到删除和插入计数中.有没有办法让 diffstat 做同样的事情?

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

我在这个命令的输出中添加了问题中 diffstat 命令吐出的删除 (-) 计数,以获得实际的删除计数,对于插入 (+) 计数也是如此。

更简单:

diff -urN dir1/ dir2/ |diffstat

使用 GNU diff 的 -N 选项,例如,当 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.