How to Find the Author of a Git Commit (with Email)
Finding the person behind a line of code is one of the most common tasks in Git—whether you're giving credit, asking for clarification, or (let’s be honest) finding out who broke the build.
In Git, every commit stores two distinct identities: the Author (who wrote the code) and the Committer (who put it into the repository). Usually, they are the same person, but they can differ during rebases or cherry-picks.
🔍 1. The "Quick Fix" Commands
If you just want the name and email for the most recent commit or a specific hash, use these one-liners:
- For the latest commit:
git log -1 --format="%an <%ae>" - For a specific commit (by hash):
git show -s --format="%an <%ae>" <commit-hash>
📜 2. Method: Using git log (History)
The log command is your primary tool for scanning history. By default, it shows the author's name and email, but you can customize it to be much cleaner.
Custom Formatting
Standard git log output is bulky. You can use format placeholders to get exactly what you need:
%an: Author Name%ae: Author Email%cn: Committer Name%ce: Committer Email
# Show the last 5 commits with just Name and Email
git log -5 --pretty=format:"%h - %an <%ae> : %s"
Filtering by Author
If you know the name but want to find their email or their specific contributions:
git log --author="John Doe"
🕵️ 3. Method: Using git blame (Line-by-Line)
If you are looking at a specific file and want to know who wrote Line 42, git log is too slow. You need blame.
By default, blame shows names. To see emails, add the -e flag:
git blame -e path/to/your/file.py
🛠️ 4. The "Under the Hood" Way: cat-file
For the true Git enthusiasts, you can look at the raw commit object itself. This bypasses all formatting and shows you exactly how Git stores the data on disk.
git cat-file -p <commit-hash>
Output Example:
tree 521a... parent 89b2... author Jane Doe jane@example.com 1677843000 +0000 committer Jane Doe jane@example.com 1677843000 +0000 Fixed the login bug.
⚖️ Author vs. Committer: What’s the difference?
| Role | Definition | When they differ |
|---|---|---|
| Author | The person who actually wrote the lines of code. | Always stays the same, even after a rebase. |
| Committer | The person who last applied the change to the branch. | Changes when you rebase, cherry-pick, or amend. |
Pro Tip: If you see a commit on GitHub that says "Jane Doe committed with John Smith", it usually means Jane authored the code but John merged or rebased it. You can see both using
git log --format=fuller.
📚 Sources & Technical Refs
- [1.1] Git SCM: Viewing the Commit History - Official guide on
logformatting. - [2.1] StackOverflow: How to see the author of a commit - Community discussion on Author vs Committer.
- [4.1] Git Documentation: git-blame - Detailed flags for line-level history.
📋 Copy-Pasteable Cheat Sheet
# 1. Get current author for the repo (from your config)
git config user.name
git config user.email
# 2. Get author of the LAST commit
git log -1 --format="%an <%ae>"
# 3. Get author of a SPECIFIC commit
git show -s --format="%an <%ae>" <hash>
# 4. See emails for every line in a file
git blame -e <filename>
# 5. See both Author AND Committer (if they differ)
git log -1 --format=fuller
