我正在对合并进行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(!)
我该怎么做?我目前的解决方法是通过... | diffstat -mt
输出CSV,并通过awk
手动添加列。有没有更简单的方法?
我找不到一个选项来做你想做的事。diffstat
是一种产生人类可读输出的工具,不用于机器消费。
如果你绝对必须解析/按摩它的输出,你可以使用一个非常肮脏的黑客(不推荐,可以随时中断(。定义外壳函数:
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