I have a small bash script:
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
I know that the code is not optimal. The Result of my script:
Total commits:
1000
Total no-merge commits:
817
Total merge commits:
182
Question: why is the sum of no-merge and merge commits (182+817 = 999) lower than the total commits (1000)?
The short answer is: as rarely as possible. The reason why you should use cherry-pick rarely is that it easily creates "duplicate" commits: when you integrate a commit into your HEAD branch using cherry-pick, Git has to create a new commit with the exact same contents.
Let's explain with the help of an example, suppose you have n number of commits and when you apply git squashing on them, you can squash or compress all 'n' commits into a just single commit. Git squash is used to change several large commits into a small single meaningful commit. So, you can make the git log clearer.
The output from those log commands uses \n
as a separator, not a terminator, so your wc -l
counts are all one short. You really have:
1001 = 818 + 183
commits, which adds up.
From git help log
:
The
tformat:
format works exactly likeformat:
, 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With