Git Notes
一句话解释
git notes 经独立引用为已有提交附加额外内容,不改动原提交。
用大白话说
git notes 让你为提交添加额外元数据而不重写提交本身。备注存在独立引用(默认 refs/notes/commits)并按提交哈希关联。log 时备注出现在提交信息之后。适合添加原提交中没有的信息。常见用途:在提交创建后添加代码评审评论、签署批准、CI 构建结果或 bug 跟踪引用。因备注在自有引用中,可独立 push 与 fetch(git push origin refs/notes/commits),且原提交哈希保留。备注是 amend 或 filter-branch 重写历史(会改哈希并可能扰乱协作者)的替代。它保持提交不可变同时仍可标注。缺点是备注较少使用,某些工具默认不显示。
示例
bash
# Add a note to the latest commit
git notes add -m "Reviewed-by: Ada" HEAD
# View the note in the log
git log --notes
# commit abc123...
# Author: ...
# fix: handle null input
# Notes:
# Reviewed-by: Ada
# Push notes to share with the team
git push origin refs/notes/commits
# Remove a note
git notes remove HEADnotes add 按哈希为提交附加元数据。备注存在 refs/notes/commits,与提交分离。--notes 在 log 中显示。
相关术语
相关资源
相关课程
- Git 进阶
学习 git notes。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。