git - 错误计数 git 提交

标签 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

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

Total commits:  
1000
Total no-merge commits:  
817
Total merge commits: 
182

问题:为什么非 merge 和 merge 提交的总和 (182+817 = 999) 低于总提交数 (1000)?

最佳答案

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

1001 = 818 + 183

提交,加起来。

来自 git 帮助日志:

The tformat: format works exactly like format:, except that it provides "terminator" semantics instead of "separator" semantics. In other words, each commit has the message terminator character (usually a newline) appended, rather than a separator placed between entries. This means that the final entry of a single-line format will be properly terminated with a new line, just as the "oneline" format does.

关于git - 错误计数 git 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27522719/

相关文章:

laravel - 来自 AWS Codecommit 的克隆存储库

git - 在 GitHub 上给自己分配问题

git - 如何使用 vimdiff 解决 git merge 冲突?

git - 如何 merge 到远程标签或提交 ID

git - 如何在 Windows 上设置 git ssh 的多个身份?

使用 Graphics Magick 转换命令时出现 Git fatal error

bash - bash 脚本中的 ssh 退出循环

mysql - sed 从 sql 转储中删除 DEFINER

regex - 在 bash 中修剪变量

git - Big git merge - 跨提交拆分分辨率