This error occurs when you try to view or manipulate a Git note for a commit that has no note attached, or when the note is stored in a different notes ref than expected. The fix involves specifying the correct notes reference or creating a note first.
Git notes are a way to attach additional information to commits without modifying the commits themselves. They're stored separately from the commit history in special references (typically `refs/notes/commits`). When you see "No note found for object", Git is telling you that no note exists for the specified commit in the notes reference being queried. This error commonly appears in several scenarios: 1. **No note was ever created**: The commit simply doesn't have a note attached to it. Notes must be explicitly added using `git notes add`. 2. **Notes are in a different reference**: Git supports multiple notes namespaces (like `refs/notes/commits`, `refs/notes/review`, `refs/notes/bugs`). The `git notes show` command only looks at the default notes ref unless you specify otherwise with `--ref`. 3. **Notes weren't fetched from remote**: Unlike branches and tags, notes are not fetched by default when you clone or pull a repository. They must be explicitly fetched. 4. **Configuration mismatch**: `git log` may show notes from multiple refs (via `notes.displayRef` configuration), but `git notes show` only checks the default ref unless told otherwise.
First, check which notes references exist in your repository:
# List all notes refs
git for-each-ref refs/notes
# Or check the notes directory directly
ls .git/refs/notes/Example output:
abc1234 commit refs/notes/commits
def5678 commit refs/notes/reviewThis shows you which notes namespaces are available. Common namespaces include:
- refs/notes/commits - Default namespace for general notes
- refs/notes/review - Used by Gerrit for code review data
- refs/notes/bugs - Custom namespace for bug tracking info
If no refs exist, notes may not have been created or fetched yet.
If your notes are stored in a non-default namespace, specify it with the --ref option:
# Show note from a specific ref
git notes --ref=review show HEAD
git notes --ref=bugs show abc1234
# List notes from a specific ref
git notes --ref=review listFind which ref contains your note:
# Check each known ref for notes on a commit
for ref in $(git for-each-ref --format='%(refname:short)' refs/notes/); do
echo "Checking $ref:"
git notes --ref="$ref" show HEAD 2>/dev/null && break
doneConfigure git log to show notes from all refs:
# Temporary: show notes from all refs
git log --notes='*'
# Permanent: configure displayRef
git config --add notes.displayRef refs/notes/review
git config --add notes.displayRef refs/notes/bugsNotes are not fetched by default. You need to explicitly fetch them:
# Fetch all notes from origin
git fetch origin refs/notes/*:refs/notes/*
# Fetch a specific notes ref
git fetch origin refs/notes/commits:refs/notes/commits
git fetch origin refs/notes/review:refs/notes/reviewConfigure automatic fetching of notes:
Add to your .git/config or run:
git config --add remote.origin.fetch '+refs/notes/*:refs/notes/*'After fetching, verify the notes:
# List all notes
git notes list
# Show note for specific commit
git notes show HEADFor Gerrit users: Gerrit stores review data in notes. Fetch them with:
git fetch origin refs/notes/review:refs/notes/review
git log --notes=reviewIf you want to add a note to a commit, use git notes add:
# Add a note to HEAD
git notes add -m "This is a note for the current commit"
# Add a note to a specific commit
git notes add -m "Important fix for issue #123" abc1234
# Add a note interactively (opens editor)
git notes add HEADVerify the note was created:
# Show the note
git notes show HEAD
# See the note in git log
git log -1Output with a note:
commit abc1234...
Author: Developer <[email protected]>
Date: Mon Dec 2 10:00:00 2024
Add new feature
Notes:
This is a note for the current commitAdd notes to a custom namespace:
git notes --ref=bugs add -m "Related to BUG-456" HEAD
git notes --ref=bugs show HEADWhen working with notes in CI/CD or scripts, handle the case where notes don't exist:
Check if a note exists before reading:
# Check if note exists (returns 0 if found, non-zero otherwise)
if git notes show HEAD 2>/dev/null; then
echo "Note found"
else
echo "No note for this commit"
fiGet note content or default value:
# Get note or empty string
NOTE=$(git notes show HEAD 2>/dev/null || echo "")
# Get note or create one
NOTE=$(git notes show HEAD 2>/dev/null) || {
git notes add -m "Auto-generated note"
NOTE=$(git notes show HEAD)
}List commits with notes:
# Get all objects that have notes
git notes list
# Format: <note-object-sha> <annotated-object-sha>
# 1234abc 5678def
# 9876fed 4321cbaCheck multiple notes refs in a script:
#!/bin/bash
COMMIT=${1:-HEAD}
for ref in commits review bugs custom; do
NOTE=$(git notes --ref="$ref" show "$COMMIT" 2>/dev/null)
if [ -n "$NOTE" ]; then
echo "Found in refs/notes/$ref:"
echo "$NOTE"
exit 0
fi
done
echo "No notes found for $COMMIT"After creating or modifying notes, you need to push them explicitly:
# Push default notes ref
git push origin refs/notes/commits
# Push all notes refs
git push origin 'refs/notes/*'
# Push a specific notes ref
git push origin refs/notes/reviewSet up automatic pushing:
# Configure push refspec for notes
git config --add remote.origin.push '+refs/notes/*:refs/notes/*'Force push notes (use with caution):
# If notes diverged, you may need to force push
git push --force origin refs/notes/commitsWarning: Force pushing notes can overwrite others' annotations. Coordinate with your team if sharing notes.
After applying the appropriate fix, verify notes work correctly:
# List all notes refs
git for-each-ref refs/notes
# List all notes in default ref
git notes list
# Show note for HEAD
git notes show HEAD
# View notes in log output
git log -3 --notes
# View notes from all refs
git log -3 --notes='*'Test creating and viewing a note:
# Create a test note
git notes add -m "Test note" HEAD
# Verify it shows
git notes show HEAD
# Clean up (optional)
git notes remove HEADIf issues persist:
1. Check Git version: git --version (notes support varies)
2. Verify repository integrity: git fsck
3. Check for corrupted refs: git for-each-ref refs/notes
4. Inspect the notes ref directly: git log refs/notes/commits
### Understanding Git Notes Architecture
Git notes are stored as a separate tree that maps object SHAs to note content. The notes ref (e.g., refs/notes/commits) points to a commit whose tree contains the notes data:
# View the notes tree structure
git ls-tree refs/notes/commits
# Notes use a sharded directory structure for performance:
# ab/cd1234... (first 2 chars / rest of SHA)### Notes and Repository Cloning
When cloning a repository, notes are NOT included by default:
# Clone with notes
git clone --origin origin <url>
cd <repo>
git fetch origin refs/notes/*:refs/notes/*For automation/CI, configure in `.gitconfig`:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/notes/*:refs/notes/*### Common Notes Ref Conventions
| Namespace | Usage |
|-----------|-------|
| refs/notes/commits | Default, general-purpose notes |
| refs/notes/review | Gerrit code review data |
| refs/notes/amend | Amendment history tracking |
| refs/notes/rewrite | Rebase/cherry-pick tracking |
### Notes Merge Strategies
When notes conflict (e.g., multiple developers adding notes):
# Merge notes from another ref
git notes merge refs/notes/commits
# Available strategies:
git notes merge -s manual # Manual resolution (default)
git notes merge -s ours # Keep local notes
git notes merge -s theirs # Accept remote notes
git notes merge -s union # Concatenate both
git notes merge -s cat_sort_uniq # Combine, sort, deduplicate### Performance Considerations
For repositories with many notes, consider:
1. Fanout structure: Git automatically uses a hierarchical storage when notes exceed certain thresholds
2. Pruning orphaned notes: git notes prune removes notes for objects that no longer exist
3. Separate clones: For CI systems that only need notes temporarily, fetch into a detached refs namespace
### Integration with Code Review Systems
Gerrit: Stores extensive review metadata in notes. After fetching:
git fetch origin refs/notes/review:refs/notes/review
git log --notes=reviewGitHub/GitLab: Don't use notes for PR/MR data (they use their API instead). Notes pushed to these platforms are preserved but not displayed in the web UI.
### Debugging Notes Issues
# Show the note object for a commit
git notes list HEAD
# Show the note commit history
git log refs/notes/commits
# Diff notes between refs
git diff refs/notes/commits refs/notes/review
# Find orphaned notes
git notes prune -n # Dry run
git notes prune # Actually removewarning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server