git-notes
is used to add or inspect object notes. How can I delete a git-notes
commit, so the commit of git-notes command will not exist in git history. I want to delete git-notes commit, I'm not mean the "git-notes remove", which only remove that notes and make another commit.
Asked
Active
Viewed 5,693 times
10
-
Please refer to this answer - http://stackoverflow.com/a/18507031 – Igor Oct 14 '14 at 13:01
-
@Igor IMO that doesn’t answer the question. It seems that OP wants to delete a specific commit created by git-notes(1). As in: similar to removing a commit with git-rebase(1). – Guildenstern May 03 '23 at 12:51
3 Answers
13
As git stores notes on a non-branch ref (pointed by refs/notes/commits
by default), you can create a branch, pointing at notes head, edit it as usual (using rebase
, for example), and update notes reference to the tip of that branch:
// create branch pointing to the tip of notes branch
git checkout -B notes-editing refs/notes/commits
// do whatever you want with notes-editing branch
// for example, git reset --hard HEAD^ to remove last commit
// reset notes reference to the tip of temporary branch
git update-ref refs/notes/commits notes-editing
// remove temporary branch
git checkout master
git branch -D notes-editing
To completely remove the notes (from the current repo), you need to delete the notes/commits
reference, but removing the file might not be sufficient, better to do it properly:
git update-ref -d refs/notes/commits

Eli Barzilay
- 29,301
- 3
- 67
- 110

max
- 33,369
- 7
- 73
- 84
-
the last step: `git branch -D` does not delete `git notes` commits as the usual branch. – Fei Aug 06 '12 at 14:45
-
4You want to remove all notes completely? Then you should just remove `.git/refs/notes/commits` file. – max Aug 06 '12 at 15:34
-
@max I think removing `.git/refs/notes/commits` would only remove the (local) reference to the notes, but not the actual note objects – Daniel Serodio Oct 29 '14 at 23:19
-
if there is only one note (one commit) and we want to remove it, git reset HEAD^ returns "fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree" – user2518618 Jan 29 '15 at 15:02
-
1The only solution that worked for me was removing `.git/refs/notes/commits` as @max points out and then run `git gc` – user2518618 Jan 29 '15 at 16:18
-
4Removing `.git/refs/notes/commits` manually does not work if the notes refs has already been packed. I had to use `git update-ref -d refs/notes/commits` followed by `git gc --prune=all --aggressive`. – sschuberth Mar 30 '16 at 11:12
-3
git notes
does not create an own commit.
It could actually be used to add (git notes add
) some notes to an existing commit.
When you call git notes remove
, the notes are removed and again no own commit is made.

eckes
- 64,417
- 29
- 168
- 201
-
`git notes` does not create an own commit, however, it will be shown in history(`git log --all`). Is there any way to delete `git notes`, so that it will not be shown in history. Thank you! – Fei Aug 06 '12 at 13:43
-
Sure it (like `git notes edit`) creates commits. Just try to browse the commits with e.g. `git log refs/notes/commit`. – Guildenstern May 03 '23 at 12:53