How to Add Notes to Git Commits After the Fact with git notes
Running git notes add -m "note" <commit> attaches a note to a commit without changing the commit itself. Because the commit isn't recreated, its hash stays the same. Use this command when you want to keep information alongside the commit history that you didn't have at commit time, such as the date it was deployed to production or where a bug was reported.
I tested on Ubuntu 24.04 with Git 2.43.0. The author and committer name and email are example values (Neko <neko@example.com>). Dates were set with environment variables, and the pager was turned off. For adding notes, I passed the message with -m each time. I did not test writing notes in an editor (such as git notes edit), carrying notes over during rebase, cases where merging notes produces conflicts, or how notes display on services such as GitHub.
- 1. History before adding a note
- 2. Adding a note with git notes add
- 3. Use append to add to a note, and -f to replace it
- 4. Showing and hiding notes in git log
- 5. Notes are stored in a separate ref, refs/notes/commits
- 6. Separating notes by purpose (–ref)
- 7. Removing a note (remove)
- 8. Recreating a commit with amend does not carry the note over
- 9. Sharing notes by pushing them
- 10. With a + refspec, local-only notes are lost on fetch
- 11. Without +, fetch is rejected, and git notes merge combines the notes
History before adding a note
I tested in a repository named app that has three commits. Before adding any note, git log looks like this. git notes list prints nothing because there are no notes yet.
$ git log --oneline
5a2ee51 トップ画面を追加
a311519 ログイン画面を追加
e563966 最初のコミット
$ git log -1 HEAD~1
commit a3115192c799fb8661d6d19f0fa0acd511b7c69d
Author: Neko <neko@example.com>
Date: Mon Nov 2 10:00:00 2026 +0900
ログイン画面を追加
$ git notes list
Adding a note with git notes add
I attached a note to the second commit (HEAD~1). If you don't specify a commit, the note goes on HEAD.
$ git notes add -m "本番には11月5日に反映済み" HEAD~1
$ git log -1 HEAD~1
commit a3115192c799fb8661d6d19f0fa0acd511b7c69d
Author: Neko <neko@example.com>
Date: Mon Nov 2 10:00:00 2026 +0900
ログイン画面を追加
Notes:
本番には11月5日に反映済み
A Notes: line appears below the commit message, and the note text is indented under it. The commit hash (a311519…) is the same as before. In git log --oneline, all three commits keep their hashes.
$ git log --oneline
5a2ee51 トップ画面を追加
a311519 ログイン画面を追加
e563966 最初のコミット
To see only the note text, use git notes show. To list the commits that have notes, use git notes list. Each line of list shows, on the left, the object that holds the note text and, on the right, the commit the note is attached to.
$ git notes show HEAD~1
本番には11月5日に反映済み
$ git notes list
08a2bc6bccb777e775810b7306a05b882bad977c a3115192c799fb8661d6d19f0fa0acd511b7c69d
The git notes reference also lists, as one use for notes, supplementing a commit message without changing the commit itself.
Use append to add to a note, and -f to replace it
When I ran git notes add again on a commit that already had a note, it stopped with an error. The original note was kept.
$ git notes add -m "別のメモ" HEAD~1
error: Cannot add notes. Found existing notes for object a3115192c799fb8661d6d19f0fa0acd511b7c69d. Use '-f' to overwrite existing notes
To add text after the existing note, use git notes append. A blank line was inserted between the earlier note and the new one.
$ git notes append -m "不具合の報告: https://example.com/issues/12" HEAD~1
$ git notes show HEAD~1
本番には11月5日に反映済み
不具合の報告: https://example.com/issues/12
To replace the whole note, add -f to add, as the error message suggests. The new note replaced everything, including the second paragraph I had appended.
$ git notes add -f -m "本番には11月6日に反映済み(5日は取り消し)" HEAD~1
Overwriting existing notes for object a3115192c799fb8661d6d19f0fa0acd511b7c69d
$ git notes show HEAD~1
本番には11月6日に反映済み(5日は取り消し)
Showing and hiding notes in git log
Plain git log and git show display notes without any extra option. With git show --stat, the note appeared above the list of changed files.
$ git show --stat HEAD~1
commit a3115192c799fb8661d6d19f0fa0acd511b7c69d
Author: Neko <neko@example.com>
Date: Mon Nov 2 10:00:00 2026 +0900
ログイン画面を追加
Notes:
本番には11月6日に反映済み(5日は取り消し)
login.txt | 1 +
1 file changed, 1 insertion(+)
On the other hand, right after adding the note, git log --oneline did not show it. The --notes entry in the git log reference also says that notes are shown by default only when --pretty, --format, and --oneline are not given. To see notes with --oneline, add --notes.
$ git log --oneline --notes
5a2ee51 トップ画面を追加
a311519 ログイン画面を追加
Notes:
本番には11月6日に反映済み(5日は取り消し)
e563966 最初のコミット
When you set the format with --format, %N is replaced by the note. In this output, a blank line followed each commit that has a note.
$ git log --format="%h %s / %N" -3
5a2ee51 トップ画面を追加 /
a311519 ログイン画面を追加 / 本番には11月6日に反映済み(5日は取り消し)
e563966 最初のコミット /
Conversely, to hide notes in plain git log, use --no-notes.
$ git log -1 --no-notes HEAD~1
commit a3115192c799fb8661d6d19f0fa0acd511b7c69d
Author: Neko <neko@example.com>
Date: Mon Nov 2 10:00:00 2026 +0900
ログイン画面を追加
Notes are stored in a separate ref, refs/notes/commits
Notes are not stored inside the commits. They are stored in a separate ref, refs/notes/commits. Each time a note changes, a new commit is added to this ref. So far I have run add, append, and add -f, which gives three commits. The author is taken from user.name in git config, the same as for regular commits.
$ git log --format="%h %an %ad %s" --date=iso refs/notes/commits
c7a1d0f Neko 2026-11-10 10:10:00 +0900 Notes added by 'git notes add'
5a3e3f9 Neko 2026-11-10 10:05:00 +0900 Notes added by 'git notes append'
904d75e Neko 2026-11-10 10:00:00 +0900 Notes added by 'git notes add'
The tree of this ref contains one file for each commit that has a note, named after that commit's hash.
$ git ls-tree refs/notes/commits
100644 blob 77441ebdafabb021867c0743982e8a6c8edb3616 a3115192c799fb8661d6d19f0fa0acd511b7c69d
Separating notes by purpose (–ref)
With --ref, you can attach notes to a ref other than refs/notes/commits. --ref=review creates refs/notes/review. I added a review note to the latest commit.
$ git notes --ref=review add -m "レビュー: 確認済み" HEAD
$ git log -1 HEAD
commit 5a2ee51edf5132a4cd101f2fd219c5e291cb8a80
Author: Neko <neko@example.com>
Date: Tue Nov 3 10:00:00 2026 +0900
トップ画面を追加
A plain git log shows only the notes in refs/notes/commits. The review note did not appear. To see it, add --notes=review. The heading becomes Notes (review):, which shows which ref the note comes from.
$ git log -1 --notes=review HEAD
commit 5a2ee51edf5132a4cd101f2fd219c5e291cb8a80
Author: Neko <neko@example.com>
Date: Tue Nov 3 10:00:00 2026 +0900
トップ画面を追加
Notes (review):
レビュー: 確認済み
With --notes="*", notes from every ref under refs/notes/ are shown. When I showed the latest two commits, the first one displayed the review note and the second one displayed the note from refs/notes/commits.
$ git log -2 --notes="*"
commit 5a2ee51edf5132a4cd101f2fd219c5e291cb8a80
Author: Neko <neko@example.com>
Date: Tue Nov 3 10:00:00 2026 +0900
トップ画面を追加
Notes (review):
レビュー: 確認済み
commit a3115192c799fb8661d6d19f0fa0acd511b7c69d
Author: Neko <neko@example.com>
Date: Mon Nov 2 10:00:00 2026 +0900
ログイン画面を追加
Notes:
本番には11月6日に反映済み(5日は取り消し)
$ git for-each-ref refs/notes
c7a1d0f59e1ce1f4204efe9281fa7c9f025cd367 commit refs/notes/commits
ea65a0bd80525fdab5b70e27d6c0737d16bef9b6 commit refs/notes/review
Removing a note (remove)
To delete a note, use git notes remove. With --ref, it removes the note from that ref. After removing it, list printed nothing.
$ git notes --ref=review remove HEAD
Removing note for object HEAD
$ git notes --ref=review list
Recreating a commit with amend does not carry the note over
Notes are tied to the commit hash. When you recreate a commit with git commit --amend, the hash changes. I added a note to the latest commit and then amended it. The git log of the new commit did not show the note.
$ git notes add -m "あとで文言を見直す" HEAD
$ git commit -q --amend -m "トップ画面を追加する"
$ git log -1 HEAD
commit 2bc1d2bc0e25e0b8e83c8c8bbb138a4dc4c1f53f
Author: Neko <neko@example.com>
Date: Tue Nov 3 10:00:00 2026 +0900
トップ画面を追加する
$ git notes list
d9f667026a9b927fd18c19a547b95de584354756 5a2ee51edf5132a4cd101f2fd219c5e291cb8a80
77441ebdafabb021867c0743982e8a6c8edb3616 a3115192c799fb8661d6d19f0fa0acd511b7c69d
$ git config notes.rewriteRef
In git notes list, the note is still attached to the commit before the rewrite (5a2ee51). According to the notes.rewriteRef entry in the git config reference, this setting has no default value, and if it is not set, notes are not copied during amend or rebase. Setting refs/notes/commits makes notes that were added without --ref (the notes in refs/notes/commits) get copied.
After setting it, I added a note again and amended. This time the note also appeared on the new commit (f653a90).
$ git config notes.rewriteRef refs/notes/commits
$ git notes add -m "あとで文言を見直す" HEAD
$ git commit -q --amend -m "トップ画面を追加した"
$ git log -1 HEAD
commit f653a909241cdf17243876576d351dbdfdb8fe3d
Author: Neko <neko@example.com>
Date: Tue Nov 3 10:00:00 2026 +0900
トップ画面を追加した
Notes:
あとで文言を見直す
$ git notes list
d9f667026a9b927fd18c19a547b95de584354756 2bc1d2bc0e25e0b8e83c8c8bbb138a4dc4c1f53f
d9f667026a9b927fd18c19a547b95de584354756 5a2ee51edf5132a4cd101f2fd219c5e291cb8a80
77441ebdafabb021867c0743982e8a6c8edb3616 a3115192c799fb8661d6d19f0fa0acd511b7c69d
d9f667026a9b927fd18c19a547b95de584354756 f653a909241cdf17243876576d351dbdfdb8fe3d
The note was copied, not moved. The same note also remained on the commit before the rewrite (2bc1d2b).
Sharing notes by pushing them
Notes live in a separate ref, so pushing a branch alone does not send them. I created a shared repository (remote.git) and pushed refs/notes/commits separately from the branch.
$ git init -q --bare remote.git
$ git remote add origin ../remote.git
$ git push -q origin main
$ git push origin refs/notes/commits
To ../remote.git
* [new reference] refs/notes/commits -> refs/notes/commits
The same applies on the receiving side: cloning alone does not bring the notes. In the cloned repository, git log for the commit with the note showed no Notes: section, and git notes list was empty.
$ git clone -q remote.git copy
$ git log -1 HEAD~1
commit a3115192c799fb8661d6d19f0fa0acd511b7c69d
Author: Neko <neko@example.com>
Date: Mon Nov 2 10:00:00 2026 +0900
ログイン画面を追加
$ git notes list
In the cloned repository, I added refs/notes/* to the refspec that controls which refs fetch brings down (remote.origin.fetch) and then fetched. The notes arrived. This setting is saved in the repository, so from then on git fetch alone also fetches the notes.
$ git config --add remote.origin.fetch "+refs/notes/*:refs/notes/*"
$ git config --get-all remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
+refs/notes/*:refs/notes/*
$ git fetch -q
$ git for-each-ref refs/notes
ab6d9ad94e32f2629a3927d46c1ff26bdf89106b commit refs/notes/commits
$ git log -1 HEAD~1
commit a3115192c799fb8661d6d19f0fa0acd511b7c69d
Author: Neko <neko@example.com>
Date: Mon Nov 2 10:00:00 2026 +0900
ログイン画面を追加
Notes:
本番には11月6日に反映済み(5日は取り消し)
With a + refspec, local-only notes are lost on fetch
The +refs/notes/*:refs/notes/* line I added in the previous section starts with +. With this setting in place, I tried fetching while a note existed locally that had not been pushed yet.
In the cloned repository (copy), I added a note to the first commit (HEAD~2).
$ git notes add -m "手元だけのメモ" HEAD~2
$ git notes show HEAD~2
手元だけのメモ
Then, in the original repository (app), I appended a note to a different commit and pushed refs/notes/commits.
$ git notes append -m "共有用に書き足したメモ" HEAD~1
$ git push -q origin refs/notes/commits
When I went back to copy and fetched, refs/notes/commits was replaced with a (forced update). The exit code was 0 and no error was printed. The appended note arrived, but the note I had attached to HEAD~2 was gone. (The From line includes the path of the working directory, so I removed it with grep -v.)
$ git fetch -v origin 2>&1 | grep -v "^From"; echo "exit=${PIPESTATUS[0]}"
= [up to date] main -> origin/main
+ 01ad079...5696049 refs/notes/commits -> refs/notes/commits (forced update)
exit=0
$ git notes show HEAD~2
error: no note found for object e5639665d087edf66b4a5c0d6760c5eec4b83069.
$ git notes show HEAD~1
本番には11月6日に反映済み(5日は取り消し)
共有用に書き足したメモ
If +refs/notes/*:refs/notes/* is in your fetch configuration, and the notes in the shared repository and your local notes diverge, local notes that have not been pushed are deleted without any error. If you want to keep local notes, remove the + as in the next section and combine the notes with git notes merge.
Without +, fetch is rejected, and git notes merge combines the notes
I removed the + from the notes line in remote.origin.fetch and tried the same steps again. The final "notes" in --replace-all is a regular expression that selects which line to replace, so only the line containing notes is replaced.
$ git config --replace-all remote.origin.fetch "refs/notes/*:refs/notes/*" "notes"
$ git config --get-all remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
refs/notes/*:refs/notes/*
$ git notes add -m "手元だけのメモ(2回目)" HEAD~2
In app, I appended another note and pushed.
$ git notes append -m "共有用に書き足したメモ(2回目)" HEAD~1
$ git push -q origin refs/notes/commits
This time the fetch was rejected with (non-fast-forward), and the exit code was 1. The local notes were kept. However, the second note I appended in app did not arrive.
$ git fetch -v origin 2>&1 | grep -v "^From"; echo "exit=${PIPESTATUS[0]}"
= [up to date] main -> origin/main
! [rejected] refs/notes/commits -> refs/notes/commits (non-fast-forward)
exit=1
$ git notes show HEAD~2
手元だけのメモ(2回目)
$ git notes show HEAD~1
本番には11月6日に反映済み(5日は取り消し)
共有用に書き足したメモ
To keep both sets of notes, fetch the shared repository's notes into a ref with a different name (here refs/notes/origin-commits), and then combine them into the local refs/notes/commits with git notes merge. According to the git notes reference, if the same commit's note was rewritten on both sides and the results conflict, the default strategy is manual, which requires you to resolve the conflict by hand. In this test, no commit had been rewritten on both sides, so the merge completed without any prompt.
$ git fetch -q origin refs/notes/commits:refs/notes/origin-commits
$ git notes merge refs/notes/origin-commits
$ git notes show HEAD~2
手元だけのメモ(2回目)
$ git notes show HEAD~1
本番には11月6日に反映済み(5日は取り消し)
共有用に書き足したメモ
共有用に書き足したメモ(2回目)
After merging, refs/notes/commits could be pushed without being rejected.
$ git push -q origin refs/notes/commits
$ git ls-remote origin refs/notes/commits
bb7e7896fcba81e31516859e69e2a59d9276be2b refs/notes/commits




