← 返回命令列表

Linux command

git-notes 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Add note to HEAD

git notes add -m "[note text]"

Add note to specific commit

git notes add -m "[note]" [commit]

Show notes

git notes show [commit]

List all notes

git notes list

Edit existing note

git notes edit [commit]

Append text

git notes append -m "[more text]" [commit]

Copy a note

git notes copy [from_commit] [to_commit]

Remove note

git notes remove [commit]

Push notes

git push origin refs/notes/*

Fetch notes

git fetch origin refs/notes/*:refs/notes/*

说明

git notes adds metadata to commits without modifying them. Notes are stored as separate refs under refs/notes/, allowing annotations, code review comments, build status, or other metadata to be attached after commits are created and even after they have been pushed. Notes can be organized in namespaces using the --ref option. Since notes don't change commit hashes, they provide a non-destructive way to enrich commit history with additional context. The default notes ref is refs/notes/commits, but you can keep separate notes namespaces (e.g. refs/notes/review, refs/notes/build) by using --ref or by setting core.notesRef in git config.

参数

add
Add a new note to the given object (default: HEAD). Fails if a note already exists unless -f is used.
show
Print the note for the given object.
list
List notes for the given object, or list all notes if no object is specified.
edit
Edit existing note in the configured editor.
append
Append new content to an existing note.
copy _from_ _to_
Copy the note from one object to another.
remove
Remove notes for the given objects.
prune
Remove notes attached to objects that no longer exist.
merge _ref_
Merge notes from another notes ref.
get-ref
Print the current notes ref.
-m _MSG_
Use given message as the note text.
-F _FILE_
Read note text from a file.
-C _OBJECT_
Reuse note from given object.
-c _OBJECT_
Reuse and edit note from given object.
-f, --force
Overwrite an existing note.
--ref _REF_
Use the given notes ref instead of the default refs/notes/commits.

FAQ

What is the git-notes command used for?

git notes adds metadata to commits without modifying them. Notes are stored as separate refs under refs/notes/, allowing annotations, code review comments, build status, or other metadata to be attached after commits are created and even after they have been pushed. Notes can be organized in namespaces using the --ref option. Since notes don't change commit hashes, they provide a non-destructive way to enrich commit history with additional context. The default notes ref is refs/notes/commits, but you can keep separate notes namespaces (e.g. refs/notes/review, refs/notes/build) by using --ref or by setting core.notesRef in git config.

How do I run a basic git-notes example?

Run `git notes add -m "[note text]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does add do in git-notes?

Add a new note to the given object (default: HEAD). Fails if a note already exists unless -f is used.