如何强制 diffstat 始终显示插入、删除和修改的数量,即使是零值?

问题描述 投票:0回答:1

我正在合并中执行

diffstat
来查看我做了多少插入、删除 修改:

git show 526162eed6 --first-parent --unified=0 | diffstat -m

这列出了所有文件并在最后给出了摘要:

a/b/c | 10 ++++++++++
a/b/d |  5 +++++
...
10 files changed, 50 insertions(+), 10 modification(!)

但是,我想看到 all 值,即使它们为零:

10 files changed, 50 insertions(+), 0 deletions(-), 10 modifications(!)

我该怎么做?我当前的解决方法是通过

... | diffstat -mt
输出 CSV,并通过
awk
手动添加列。有没有更简单的方法?

git diff diffstat
1个回答
1
投票

我找不到做你想做的事的选项。

diffstat
是一种生成人类可读输出的工具,不适合机器使用。

如果你绝对必须解析/修改它的输出,你可以使用一个非常肮脏的黑客(不推荐,可以随时破坏)。定义 shell 函数:

stats() {
  read -r stat
  echo "$stat" | grep -o '[0-9]\+ file' | grep -o '[0-9]\+' || echo '0'
  echo 'files changed,' # does not match original output for 1 file
  echo "$stat" | grep -o '[0-9]\+ ins' | grep -o '[0-9]\+' || echo '0'
  echo 'insertions(+),'
  echo "$stat" | grep -o '[0-9]\+ del' | grep -o '[0-9]\+' || echo '0'
  echo 'deletions(-),'
  echo "$stat" | grep -o '[0-9]\+ mod' | grep -o '[0-9]\+' || echo '0'
  echo 'modifications(!)'
}
diffstats() {
  diffstat -sm | stats | paste -sd ' '
}

然后:

git diff | diffstats
© www.soinside.com 2019 - 2024. All rights reserved.