I am searching for git commands to get all commits of an author. There are a lot of options available to do this. For example
git log --author="<author>" --pretty="%H"
Using name of an author within <> provides different number of commits with respect to email address of the author.
The similar thing happens if I use git shortlog -sn and git shortlog -sne.
Why the number of commits is different for using name vs email?
People commit with slightly different identities all the time. Maybe they use both their work email and their personal email. That could happen because they initially committed with their default identity which had their personal email. Later they fixed it for the repository to use their work email. Then later they might have changed jobs.
But that doesn't have to matter. You can normalize them to a single identity by using the gitmailmap(5) format. Place a .mailmap file at the root of the repository and normalize the names. git-log(1) will respect this file (because log.mailmap is true by default.) I think other high-level (porcelain) commands will respect it as well.
Look out for options like --mailmap and --no-mailmap to turn this normalization on and off per command invocation.
You're seeing different results because Git treats the user.name and user.email as plain strings and doesn't enforce users having a single identity. So, "John Doe" and "John D." are considered different people even if they really are the same. See 8.1 Customizing Git - Git Configuration. Any contributor with push access can set these arbitrarily (with some exceptions1).
Even cloud platforms like GitHub and Azure DevOps will allow users to author commits with arbitrary metadata. There have been notable examples of users spoofing well-known names.
It'd be difficult to speculate on why this particular user's name/email changed. Perhaps they simply decided to change it. They may also be working across multiple environments with inconsistent configuration. Some new developers may not recognize that they're committing under one email while meaning to use another.
As a simplified example, recreate this by using the git config command to update the user.name and user.email between two commits. I'm still the same person, but Git referenced the config to set the Author and that's reflected in the log:
git init -b main
user.name and user.email in the Git Config, then commit your changesecho "Hello" > hello.txt
git config user.name "John D."
git config user.email [email protected]
git add .
git commit -m "Hello from John D."
user.name and user.emailecho "Hello, John D!" >> hello.txt
git config user.name "John Doe"
git config user.email [email protected]
git add .
git commit -m "Hello from John Doe"
git log --allcommit df18055b4483586d5a62ad9858e1350d3d847200 (HEAD -> main)
Author: John Doe <[email protected]>
Date: Tue Jul 29 00:37:21 2025 -0400
Hello from John Doe
commit 725a60ec168fc45521f5a34fc86132e6287eefd1
Author: John D. <[email protected]>
Date: Tue Jul 29 00:36:09 2025 -0400
Hello from John D.
1 Some Git servers use hooks to reject commits based on author metadata.
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