Questions tagged [git-notes]

A typical use of git notes is to supplement a commit message without changing the commit itself. Notes can be shown by git log along with the original commit message. To distinguish these notes from the message stored in the commit object, the notes are indented like the message, after an unindented line saying "Notes ():" (or "Notes:" for refs/notes/commits).

When files are committed into a Git repository, they are addressed by a hash of the contents. The same is true of trees and commits. One of the benefits of this structure is that the objects cannot be modified after they have been committed (since doing so would change that hash).

However, sometimes it is desirable to be able to add metadata to a commit after it has already been committed. There are three ways of doing this:

Amend the commit message to add in the additional metadata, accepting this will change the branch. Create a merge node with a more detailed commit, and push that (so that the previous commit is retained and can be fast forwarded). Add additional metadata in the form of git notes. Of these three options, only the last one will not change the current branch.

Git Notes are, in effect, a separate ‘branch’ of the repository (stored at .git/refs/notes). They don’t show up in the git branch command (that lists .git/refs/heads by default). However, although you could check it out and manually update it, there is a command provided which helps you do that; git notes.

By default, notes are saved to and read from refs/notes/commits, but this default can be overridden. See the OPTIONS, CONFIGURATION, and ENVIRONMENT sections below. If this ref does not exist, it will be quietly created when it is first needed to store a note.

To change which notes are shown by git log, see the "notes.displayRef" configuration in git-log.

You can use notes to add annotations with information that was not available at the time a commit was written. e.g.

   $ git notes add -m 'Tested-by: Rachel Gallen<rg@kdbg.net>' 72a144e2
   $ git show -s 72a144e
   [...]
         Signed-off-by: Ruth Escat<gitster@pobox.com>

   Notes:
         Tested-by: Rachel Gallen <rg@kdbg.net>

Source

38 questions
48
votes
3 answers

git: How to delete a local ref branch?

I have bit of a difficulty in deleting a local ref branch(refs/notes/origin/commits). I was able to delete the branch(refs/notes/origin/commits) in the remote repository using the command git push origin :refs/notes/origin/commits but when i try to…
Iowa
  • 2,171
  • 4
  • 22
  • 31
16
votes
1 answer

Git notes details

I've read this and this but still see them as obscure. By far understood: creation (git notes add -m "a note") notes are namespaced Questions: notes seem not to create a commit, so how the push (example) is possible for them? what is the…
Max
  • 1,741
  • 3
  • 23
  • 40
14
votes
1 answer

Is there a way to automatically merge notes if commits for those notes get squashed?

For example: git commit -am "Something" git notes append -m "Dark " git commit -am "Something" git notes append -m "Side" git rebase -i # now I squash two commits and I expect to see "Dark Side" here # but it show that note is undefined git notes…
Andrew
  • 8,330
  • 11
  • 45
  • 78
13
votes
1 answer

Fetch git notes when cloning

I know that git notes can be fetched after cloning using: git fetch origin refs/notes/*:refs/notes/* or even be setup in git config to be always fetched. However at clone time I do not get the notes, so I have to clone and then fetch. Although I do…
Zitrax
  • 19,036
  • 20
  • 88
  • 110
12
votes
3 answers

How to get the tree hash for a given directory name?

I'd like to attach a note to a tree object. However, in order to do so I first need to know the tree object's hash. For a given directory name that's part of my repository, how do I get its belonging tree object's hash in order to attach a note to…
sschuberth
  • 28,386
  • 6
  • 101
  • 146
12
votes
1 answer

Preserve git notes when rewriting history with git filter branch

For some reasons, I have to rewrite the entire history of my git repository to change the committer_id of every commit. However, I attached a note to more or less every commit and using git-filter-branch to change the committer_id will logically…
Kiplaki
  • 171
  • 6
10
votes
2 answers

Merging git notes when there are merge conflicts in them

I followed these instructions in order to merge Git notes. I cloned a repo, added notes reference to the commit (refs/notes/commits). When i push it, central repo rejects it as it was non-fast forward—because there was already a refs/notes/commits…
maxmelbin
  • 2,045
  • 3
  • 21
  • 29
8
votes
2 answers

Store custom metadata against individual files in a Git repository

I'm working with a Git repository and would like to define custom properties to apply to each file in the repository. These properties could then be updated on each commit. Ideally the properties should be easily searchable and eventually…
user5754
  • 147
  • 1
  • 7
7
votes
2 answers

git notes after BFG?

I migrated from SVN to git and i had a note in each git commit referencing to SVN revision number. After repo import i used BFG repo cleaner to clean git history from binary files and other trash. Unfortunately now i do not see notes when i type…
Kirill
  • 6,762
  • 4
  • 51
  • 81
5
votes
3 answers

Find commit with specific git note

I use git notes in my repository. Sometimes I need to find a commit with note that includes given string. So far I was using this command: git log --show-notes=* --grep="PATTERN" --format=format:%H The problem here is that this prints every commit…
Zuku
  • 1,030
  • 13
  • 21
5
votes
2 answers

Git: Get all notes of a branch

We'd like to annotate our commits with git notes add, which works fine. To get a list of all commits with notes we use this command git notes | cut -d' ' -f2 | xargs -ihash git log hash -1 Now we are looking for the notes of a branch only. I'm at…
BetaRide
  • 16,207
  • 29
  • 99
  • 177
5
votes
2 answers

Is it possible to get git to automatically update notes on the remote server when I do a git push/git pull

Currently if I add notes to an object in git I have to explicitly push/pull this information to the remote server. Is it possible to configure git so that when I do a git push it will push my local notes changes as well as any local source…
DaveG
  • 143
  • 1
  • 2
  • 5
4
votes
4 answers

How to show remote refs/notes/* with git log

How to show refs/notes in a git log --oneline --graph --all --decorate output for remotes? With the above command I only see my own refs/notes/foobar, but not the remote ref. The docs don't hint any command I could possibly use for this.
musicmatze
  • 4,124
  • 7
  • 33
  • 48
4
votes
1 answer

Can a ref stored outside refs/heads be considered a branch and checked-out and worked-on as a normal branch?

Now, I don't know if a ref is considered to be a branch only if it's inside refs/heads, and indeed the question was previously titled How to checkout a branch stored outside refs/heads?. So I'm not sure if refs stored outside refs/heads can still be…
gbr
  • 1,264
  • 8
  • 27
4
votes
3 answers

How to make sure others people cannot edit my git notes?

I want to make release notes by using git notes, but I am not sure if other people change my git notes by using the same ref. BTW, chmod 444 .git/refs/notes/abc_test & .git/logs/refs/notes/abc_test does not work.
Flyakite
  • 109
  • 8
1
2 3