git - 即使对于零值,如何强制 diffstat 始终显示插入、删除和修改的数量?
问题描述
我正在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(!)
但是,即使它们为零,我也希望查看所有值:
10 files changed, 50 insertions(+), 0 deletions(-), 10 modifications(!)
我怎样才能做到这一点?我目前的解决方法是通过输出 CSV... | diffstat -mt
并通过手动添加列awk
。有没有更简单的方法?
解决方案
我找不到做你想做的事的选项。diffstat
是一种产生人类可读输出的工具,不适合机器使用。
如果您绝对必须解析/按摩其输出,则可以使用非常肮脏的 hack(不推荐,随时可能中断)。定义外壳函数:
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
推荐阅读
- vhdl - 组件声明的用处是什么?
- python - ImportError:无法导入名称“imshow”
- javascript - PrimeNG是在你使用的时候全部进口的,还是摇摇晃晃的?我怎样才能自己确定呢?
- apache - Q: 找不到 Ngrok 配置文件
- angular - Angular:如何从自定义装饰器中获取 ElementRef
- javascript - Hide a ',' comma that repeats multiple times on a page
- python - 如何在 jupyter notebook 和终端之间匹配 python 版本?3.6.5 至 3.7
- .net - 在 MATLAB 中从 .NET 对象通过引用返回数据
- entity-framework - 在加入时包含附加参数
- unity3d - 如何将画布空间转换为世界空间