错数git提交

Dmi*_*try 5 git bash git-merge

我有一个小的bash脚本:

echo "Total commits: "
git log --all --pretty=format:"%h %ad | %s%d [%an]" --date=short | wc -l
echo "Total no-merge commits: "
git log --all --pretty=format:"%h %ad | %s%d [%an]" --date=short --no-merges | wc -l
echo "Total merge commits: "
git log --all --pretty=format:"%h %ad | %s%d [%an]" --date=short --merges | wc -l
Run Code Online (Sandbox Code Playgroud)

我知道代码不是最优的.我的脚本的结果:

Total commits:  
1000
Total no-merge commits:  
817
Total merge commits: 
182
Run Code Online (Sandbox Code Playgroud)

问题:为什么不合并和合并提交的总和(182 + 817 = 999)低于总提交(1000)?

Joe*_*Joe 8

这些日志命令的输出\n用作分隔符,而不是终结符,因此您的wc -l计数都是一个简短的.你真的有:

1001 = 818 + 183
Run Code Online (Sandbox Code Playgroud)

提交,这加起来.

来自git help log:

tformat:格式的操作完全相同format:,不同之处在于它提供了"终结者"的语义,而不是"分隔符"的语义.换句话说,每个提交都附加了消息终止符(通常是换行符),而不是在条目之间放置的分隔符.这意味着单行格式的最终​​输入将使用新行正确终止,就像"oneline"格式一样.