[背景介绍]git
git通常在生成一个commit以后,若是须要修改到commit里面的commit message的话,通常会使得commit tree自己发生变化。若是只是修改commit tree的HEAD还好,若是是修改较前的一个commit,会致使后面的commit tree全都会乱掉。咱们就须要有一种方法来保证:修改commit的commit message时,不须要动到commit tree。这就是咱们这里要介绍到的git notes。rem
[用法]it
1. 为一个commit添加notesobject
1.1. git notes [--ref $NOTE-REF] add -m "$MSG" $COMMIT进阶
1.2. 若是commit已经有notes了,这样就会abort,提示已经存在notes,那么咱们就能够加上-f参数,强制覆盖notes。grep
e.g. git notes add -f -m "$MSG"方法
-f 的用法就是force,强制盖掉本来的notes。di
1.3. 为一个commit添加一个已经存在的notescopy
git notes add [-f] -C $NOTES-IDco
1.4. 交互式添加notes
git notes edit
这会进入notes message的编辑界面,输入相应的message,而后保存退出便可。
2. 移掉一个commit的notes
git notes remove $COMMIT
3. 将commitA的notes copy到commitB
git notes copy commitA commitB
这样的用法至关于 git notes add [-f] -C $(git notes list $commitA) $commitB
4. 显示一个commit的notes
4.1.显示notes的内容
git notes show $COMMIT
4.2. 显示notes的ID
git notes list $COMMIT
5. 显示一个notes对应的commit
git notes list | grep $NOTE-ID
git notes list: 若是不指定commit,那么会列举全部的notes与对应的commit的关系
[进阶知识]
git repository里面的notes,也是采用git一向的作法,一切皆为object,一切object都会连成tree,tree即为branch。
git里面的branch通常被指代为.git/refs/heads/ 里面的那些branch,.git/refs/里面的其它都称之为reference,它们都具备branch的特性,因此说也是能够check-out的。
.git/refs/notes 里面都是各个notes的tree,能够有.git/refs/notes/tree1, 也能够有.git/refs/nots/tree2。这样就有两条notes的tree。
咱们在增,删,改,查 notes的时候,--ref $NOTES-REF就指定了具体的notes的reference。