mcpField
G
git-notes

git-notes

github.com/neolabhq開発1.8k1.1k 回インストール9 週間前に更新
リポジトリ

git-notes について

Git notes を扱うスキルです。コミットなどの Git オブジェクトの識別子を変えずにメタデータを追加できます。ノート操作、名前空間、共有、マージ、設定に加え、レビュー追跡やテスト結果の記録方法を説明します。

主な機能

  1. 01ノートの追加・表示・追記・編集・削除
  2. 02名前空間によるノートの整理
  3. 03push と fetch によるノートの共有
  4. 04ノートのマージと競合解決
  5. 05表示と書き換え動作の設定

活用シーン

  1. 01コミット上でコードレビューのコメントを追跡
  2. 02コミットにテスト結果を記録
  3. 03履歴を書き換えずに監査記録を保持
  4. 04リポジトリ間でノートを共有

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/neolabhq/context-engineering-kit --skill git-notes

インストール後、Claude Code で/git-notesを入力して読み込まれたか確認します。

詳細

Git Notes

概要

Git notes は、オブジェクト自体を変更せずに、コミット(または任意の Git オブジェクト)にメタデータを付加します。ノートは個別に保存され、コミットメッセージと並べて表示されます。

基本原則: 履歴を書き換えずに、作成後のコミットに情報を追加します。

基本概念

概念説明
ノート参照保存場所。デフォルトは refs/notes/commits です
非侵襲性ノートによって元のオブジェクトの SHA が変更されることはありません
名前空間--ref を使って異なるノートカテゴリを指定します
表示ノートは git log と git show の出力に表示されます

クイックリファレンス

タスクコマンド
ノートを追加git notes add -m "message" <sha>
ノートを表示git notes show <sha>
追記git notes append -m "message" <sha>
編集git notes edit <sha>
削除git notes remove <sha>
名前空間を使用git notes --ref=<name> <command>
ノートをプッシュgit push origin refs/notes/<name>
ノートをフェッチgit fetch origin refs/notes/<name>:refs/notes/<name>
ログに表示git log --notes=<name>

コマンドの完全なリファレンスについては、references/commands.md を参照してください。

基本的なパターン

コードレビューの追跡
# Mark reviewed
git notes --ref=reviews add -m "Reviewed-by: Alice <[email protected]>" abc1234

# View review status
git log --notes=reviews --oneline
ノートの共有
# Push to remote
git push origin refs/notes/reviews

# Fetch from remote
git fetch origin refs/notes/reviews:refs/notes/reviews
リベース後の保持
git config notes.rewrite.rebase true
git config notes.rewriteMode concatenate

よくある間違い

間違い修正方法
ログにノートが表示されない参照を指定します:git log --notes=reviews、または notes.displayRef を設定します
リベース後にノートが失われる有効にします:git config notes.rewrite.rebase true
リモートにノートがない明示的にプッシュします:git push origin refs/notes/commits
「Note already exists」エラー上書きするには -f を使い、追記するには append を使います

ベストプラクティス

実践理由
名前空間を使用する目的(レビュー、テスト、監査)ごとにノートを分けます
参照を明示するデフォルト以外のノートには常に --ref を指定します
ノートを明示的にプッシュする共有手順をチームのガイドラインに記載します
add -f より append を使うノートを蓄積するときに履歴を保持します
書き換え時の保持を設定するリベース前に git config notes.rewrite.rebase true を実行します

Git Notes コマンドリファレンス

すべての git notes コマンドとオプションの完全なリファレンスです。

基本操作

ノートを追加
# Add note to current HEAD
git notes add -m "Reviewed by Alice"

# Add note to specific commit
git notes add -m "Tested on Linux" abc1234

# Add note from file
git notes add -F review-comments.txt abc1234

# Add note interactively (opens editor)
git notes add abc1234

# Overwrite existing note
git notes add -f -m "Updated review status" abc1234

# Add empty note
git notes add --allow-empty abc1234
ノートを表示
# Show note for HEAD
git notes show

# Show note for specific commit
git notes show abc1234

# View commit with notes in log
git log --show-notes
git show abc1234

# List all notes
git notes list

# List note for specific object
git notes list abc1234

ノートを含む出力例:

commit abc1234def567890
Author: 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 existing note (creates if doesn't exist)
git notes append -m "Additional review comment" abc1234

# Append from file
git notes append -F more-comments.txt abc1234

# Append multiple messages
git notes append -m "Comment 1" -m "Comment 2" abc1234
ノートを編集
# Edit note interactively (opens editor)
git notes edit abc1234

# Edit note for HEAD
git notes edit
ノートを削除
# Remove note from HEAD
git notes remove

# Remove note from specific commit
git notes remove abc1234

# Remove notes from multiple commits
git 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 note from one commit to another
git notes copy abc1234 def5678

# Copy note to HEAD
git notes copy abc1234

# Force overwrite destination note
git notes copy -f abc1234 def5678

# Bulk copy via stdin (useful with rebase/cherry-pick)
echo "abc1234 def5678" | git notes copy --stdin
ノートを整理
# Remove notes for objects that no longer exist
git notes prune

# Dry-run to see what would be pruned
git notes prune -n

# Verbose output
git notes prune -v
ノート参照を取得
# Show current notes ref being used
git notes get-ref

複数の名前空間を使用する

ノートは、目的ごとに別々の名前空間(参照)に整理できます。

ノート参照を指定
# Add note to specific namespace
git 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 namespace
git notes --ref=reviews show abc1234

# List notes in namespace
git notes --ref=reviews list
環境変数
# Set default notes ref for session
export GIT_NOTES_REF=refs/notes/reviews
git notes add -m "Approved"

# View notes from environment ref
git notes show abc1234
複数の名前空間を表示
# Show specific notes namespace in log
git log --notes=reviews

# Show multiple namespaces
git log --notes=reviews --notes=testing

# Show all notes
git log --notes='*'

# Disable notes display
git log --no-notes

ノートのマージ

複数の参照または異なるソースにノートがある場合、それらをマージできます。

ノート参照をマージ
# Merge notes from another ref into current
git notes merge refs/notes/other

# Merge with strategy
git notes merge -s union refs/notes/other
git notes merge -s ours refs/notes/other
git notes merge -s theirs refs/notes/other
git notes merge -s cat_sort_uniq refs/notes/other

# Quiet merge
git notes merge -q refs/notes/other

# Verbose merge
git notes merge -v refs/notes/other
マージ戦略
戦略動作
manual対話形式で競合を解決します(デフォルト)
ours競合時にローカルのノートを保持します
theirs競合時にリモートのノートを保持します
union両方のノートを連結します
cat_sort_uniq連結し、行をソートして重複を削除します
マージの競合を解決
# After merge conflict with manual strategy
# Resolve conflicts in .git/NOTES_MERGE_WORKTREE/

# Commit resolved merge
git notes merge --commit

# Abort merge
git notes merge --abort

設定オプション

Git の設定
# Set default notes ref
git config notes.displayRef refs/notes/reviews

# Display multiple notes refs
git config --add notes.displayRef refs/notes/testing

# Set merge strategy for notes
git config notes.mergeStrategy union

# Set merge strategy for specific namespace
git config notes.reviews.mergeStrategy theirs

# Preserve notes during rebase
git config notes.rewrite.rebase true

# Preserve notes during amend
git config notes.rewrite.amend true

# Set rewrite mode
git config notes.rewriteMode concatenate
.gitconfig のサンプル
[notes]
    displayRef = refs/notes/reviews
    displayRef = refs/notes/testing
    mergeStrategy = union

[notes "reviews"]
    mergeStrategy = theirs

[notes.rewrite]
    rebase = true
    amend = true

ワークフローの例

コードレビューの追跡
# Mark commit as reviewed
git notes --ref=reviews add -m "Reviewed-by: Alice <[email protected]>" abc1234

# Add review comments
git notes --ref=reviews append -m "Consider extracting helper function" abc1234

# View review status
git log --notes=reviews --oneline

# Mark as approved
git notes --ref=reviews add -f -m "APPROVED by Alice" abc1234
テスト結果の注釈
# Record test pass
git notes --ref=testing add -m "Tests passed: 2024-01-15
Platform: Linux x64
Coverage: 85%" abc1234

# Record test failure
git notes --ref=testing add -m "FAILED: Integration tests
See: https://ci.example.com/build/123" def5678

# View test status across commits
git log --notes=testing --oneline
監査証跡
# Add audit note
git notes --ref=audit add -m "Security review: PASSED
Reviewer: Security Team
Date: 2024-01-15
Ticket: SEC-456" abc1234

# Query audit status
git log --notes=audit --grep="Security review"
ノートの共有
# Push notes to remote
git push origin refs/notes/reviews

# Fetch notes from remote
git fetch origin refs/notes/reviews:refs/notes/reviews

# Push all notes refs
git push origin 'refs/notes/*'

# Fetch all notes refs
git fetch origin 'refs/notes/*:refs/notes/*'
一括操作
# Add notes to all commits by author in date range
git 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 commits
git log --format="%H" HEAD~10..HEAD | xargs git notes remove --ignore-missing

コメント