Git Notes

NeoLabHQ/context-engineering-kit/antigravity/skills/git-notes

作者 NeoLabHQ23e2428e809d77717f8acc9659c374a3a1fcb93e无许可证收录于 2026年10月9日更新于 2026年10月9日

Use when adding metadata to commits without changing history, tracking review status, test results, code quality annotations, or supplementing commit messages post-hoc - provides git notes commands and patterns for attaching non-invasive metadata to Git objects.

AI 生成的概览

使用 git notes 在不改写历史的情况下为提交附加元数据的参考指南。

功能
提供 git notes 命令与模式,用于向 Git 提交及其他对象附加非侵入式元数据。内容涵盖添加、查看、追加、编辑、删除、复制和清理笔记,以及命名空间、合并、配置和通过推送与拉取共享。产出的是命令指导与工作流示例,而非文件或脚本。
适用场景
适用于需要在提交创建后添加注释而不改变其 SHA 的场景,例如跟踪评审状态、测试结果、代码质量注释或审计记录。也适合事后补充提交信息,或将笔记按用途分入不同命名空间。
运行要求
需要安装 Git 并可访问一个仓库;远程共享需要网络访问以及推送和拉取权限。不包含脚本,仅为说明文档。

Git Notes

Overview

Git notes attach metadata to commits (or any Git object) without modifying the objects themselves. Notes are stored separately and displayed alongside commit messages.

Core principle: Add information to commits after creation without rewriting history.

Core Concepts

ConceptDescription
Notes refStorage location, default refs/notes/commits
Non-invasiveNotes never modify SHA of original object
NamespacesUse --ref for different note categories
DisplayNotes appear in git log and git show output

Quick Reference

TaskCommand
Add notegit notes add -m "message" <sha>
View notegit notes show <sha>
Appendgit notes append -m "message" <sha>
Editgit notes edit <sha>
Removegit notes remove <sha>
Use namespacegit notes --ref=<name> <command>
Push notesgit push origin refs/notes/<name>
Fetch notesgit fetch origin refs/notes/<name>:refs/notes/<name>
Show in loggit log --notes=<name>

For complete command reference, see references/commands.md.

Essential Patterns

Code Review Tracking

bash
# Mark reviewedgit notes --ref=reviews add -m "Reviewed-by: Alice <[email protected]>" abc1234
# View review statusgit log --notes=reviews --oneline

Sharing Notes

bash
# Push to remotegit push origin refs/notes/reviews
# Fetch from remotegit fetch origin refs/notes/reviews:refs/notes/reviews

Preserving Through Rebase

bash
git config notes.rewrite.rebase truegit config notes.rewriteMode concatenate

Common Mistakes

MistakeFix
Notes not showing in logSpecify ref: git log --notes=reviews or configure notes.displayRef
Notes lost after rebaseEnable: git config notes.rewrite.rebase true
Notes not on remotePush explicitly: git push origin refs/notes/commits
"Note already exists" errorUse -f to overwrite or append to add

Best Practices

PracticeRationale
Use namespacesSeparate notes by purpose (reviews, testing, audit)
Be explicit about refsAlways specify --ref for non-default notes
Push notes explicitlyDocument sharing procedures in team guidelines
Use append over add -fPreserve note history when accumulating
Configure rewrite preservationRun git config notes.rewrite.rebase true before rebasing

Git Notes Command Reference

Complete reference for all git notes commands and options.

Basic Operations

Add a Note

bash
# Add note to current HEADgit notes add -m "Reviewed by Alice"
# Add note to specific commitgit notes add -m "Tested on Linux" abc1234
# Add note from filegit notes add -F review-comments.txt abc1234
# Add note interactively (opens editor)git notes add abc1234
# Overwrite existing notegit notes add -f -m "Updated review status" abc1234
# Add empty notegit notes add --allow-empty abc1234

View Notes

bash
# Show note for HEADgit notes show
# Show note for specific commitgit notes show abc1234
# View commit with notes in loggit log --show-notesgit show abc1234
# List all notesgit notes list
# List note for specific objectgit notes list abc1234

Example output with notes:

commit abc1234def567890Author: Developer <[email protected]>Date:   Mon Jan 15 10:00:00 2024 +0000
    feat: implement user authentication
Notes:    Reviewed by Alice    Tested-by: CI Bot <[email protected]>

Append to Notes

bash
# Append to existing note (creates if doesn't exist)git notes append -m "Additional review comment" abc1234
# Append from filegit notes append -F more-comments.txt abc1234
# Append multiple messagesgit notes append -m "Comment 1" -m "Comment 2" abc1234

Edit Notes

bash
# Edit note interactively (opens editor)git notes edit abc1234
# Edit note for HEADgit notes edit

Remove Notes

bash
# Remove note from HEADgit notes remove
# Remove note from specific commitgit notes remove abc1234
# Remove notes from multiple commitsgit notes remove abc1234 def5678 ghi9012
# Ignore missing notes (no error if note doesn't exist)git notes remove --ignore-missing abc1234
# Remove notes via stdin (bulk removal)echo "abc1234" | git notes remove --stdin

Copy Notes

bash
# Copy note from one commit to anothergit notes copy abc1234 def5678
# Copy note to HEADgit notes copy abc1234
# Force overwrite destination notegit notes copy -f abc1234 def5678
# Bulk copy via stdin (useful with rebase/cherry-pick)echo "abc1234 def5678" | git notes copy --stdin

Prune Notes

bash
# Remove notes for objects that no longer existgit notes prune
# Dry-run to see what would be prunedgit notes prune -n
# Verbose outputgit notes prune -v

Get Notes Reference

bash
# Show current notes ref being usedgit notes get-ref

Using Multiple Namespaces

Notes can be organized into separate namespaces (refs) for different purposes.

Specify Notes Ref

bash
# Add note to specific namespacegit notes --ref=refs/notes/reviews add -m "Approved" abc1234
# Shorthand (refs/notes/ prefix is assumed)git notes --ref=reviews add -m "Approved" abc1234
# View notes from specific namespacegit notes --ref=reviews show abc1234
# List notes in namespacegit notes --ref=reviews list

Environment Variable

bash
# Set default notes ref for sessionexport GIT_NOTES_REF=refs/notes/reviewsgit notes add -m "Approved"
# View notes from environment refgit notes show abc1234

Display Multiple Namespaces

bash
# Show specific notes namespace in loggit log --notes=reviews
# Show multiple namespacesgit log --notes=reviews --notes=testing
# Show all notesgit log --notes='*'
# Disable notes displaygit log --no-notes

Merging Notes

When notes exist in multiple refs or from different sources, they can be merged.

Merge Notes Refs

bash
# Merge notes from another ref into currentgit notes merge refs/notes/other
# Merge with strategygit notes merge -s union refs/notes/othergit notes merge -s ours refs/notes/othergit notes merge -s theirs refs/notes/othergit notes merge -s cat_sort_uniq refs/notes/other
# Quiet mergegit notes merge -q refs/notes/other
# Verbose mergegit notes merge -v refs/notes/other

Merge Strategies

StrategyBehavior
manualInteractive conflict resolution (default)
oursKeep local note on conflict
theirsKeep remote note on conflict
unionConcatenate both notes
cat_sort_uniqConcatenate, sort lines, remove duplicates

Resolve Merge Conflicts

bash
# After merge conflict with manual strategy# Resolve conflicts in .git/NOTES_MERGE_WORKTREE/
# Commit resolved mergegit notes merge --commit
# Abort mergegit notes merge --abort

Configuration Options

Git Config

bash
# Set default notes refgit config notes.displayRef refs/notes/reviews
# Display multiple notes refsgit config --add notes.displayRef refs/notes/testing
# Set merge strategy for notesgit config notes.mergeStrategy union
# Set merge strategy for specific namespacegit config notes.reviews.mergeStrategy theirs
# Preserve notes during rebasegit config notes.rewrite.rebase true
# Preserve notes during amendgit config notes.rewrite.amend true
# Set rewrite modegit config notes.rewriteMode concatenate

Sample .gitconfig

gitconfig
[notes]    displayRef = refs/notes/reviews    displayRef = refs/notes/testing    mergeStrategy = union
[notes "reviews"]    mergeStrategy = theirs
[notes.rewrite]    rebase = true    amend = true

Workflow Examples

Code Review Tracking

bash
# Mark commit as reviewedgit notes --ref=reviews add -m "Reviewed-by: Alice <[email protected]>" abc1234
# Add review commentsgit notes --ref=reviews append -m "Consider extracting helper function" abc1234
# View review statusgit log --notes=reviews --oneline
# Mark as approvedgit notes --ref=reviews add -f -m "APPROVED by Alice" abc1234

Test Results Annotation

bash
# Record test passgit notes --ref=testing add -m "Tests passed: 2024-01-15Platform: Linux x64Coverage: 85%" abc1234
# Record test failuregit notes --ref=testing add -m "FAILED: Integration testsSee: https://ci.example.com/build/123" def5678
# View test status across commitsgit log --notes=testing --oneline

Audit Trail

bash
# Add audit notegit notes --ref=audit add -m "Security review: PASSEDReviewer: Security TeamDate: 2024-01-15Ticket: SEC-456" abc1234
# Query audit statusgit log --notes=audit --grep="Security review"

Sharing Notes

bash
# Push notes to remotegit push origin refs/notes/reviews
# Fetch notes from remotegit fetch origin refs/notes/reviews:refs/notes/reviews
# Push all notes refsgit push origin 'refs/notes/*'
# Fetch all notes refsgit fetch origin 'refs/notes/*:refs/notes/*'

Bulk Operations

bash
# Add notes to all commits by author in date rangegit log --format="%H" --author="Alice" --since="2024-01-01" | \  while read sha; do    git notes add -m "Author verified" "$sha"  done
# Remove notes from range of commitsgit log --format="%H" HEAD~10..HEAD | xargs git notes remove --ignore-missing

来源与署名

来源:NeoLabHQ/context-engineering-kit位于antigravity/skills/git-notes提交23e2428

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架