I am trying to realize a use-case using git.
Use Case : It should be possible to add metadata (like Attributes) to git artifacts.
We plan to have a git repo for each component, so applying a note for each commit object could realize this requirement.
Now, it is also required that we have metadata for files within a component (git repo in this case). For this i tried to attach a note to a blob which was part of a commit.
It accepts the note and even I am able to push the notes to central repo.
Is this a safe and reliable usage of git notes for this use-case?
2012: Yes, you can use git notes that way.
The blog post "Git Tip of the Week: Git Notes" from Alex Blewitt reminds us about some of the git notes
advantages and gotcha:
the notes don’t have to be textual, nor do they have to be something which is mergeable.
They don’t even need to be on thenotes/commits
ref; you can create notes based on any reference.In fact, this is how Gerrit works (which I’ve written about before).
Gerrit stores its review information in the Git repository under notes/review. Ordinarily, this doesn’t show up (the git log only shows notes in the notes/commits refspace)
Git Notes are, in effect, a separate ‘branch’ of the repository (stored at
.git/refs/notes
)merges: since the notes file is essentially on its own branch, the content doesn’t get merged with merges between branches. If you wanted to merge git notes, then following the
Key: Value
on separate lines is the way to achieve git note merging nirvana.
The "note to self" article also points out how pushing/pulling notes isn't exactly easy.
Beside those two issues (merging and pushing), you should be ok with your 'git notes
' use case.
Note: With Git 2.39 (Q4 2022), avoid a stray empty newline in the template when creating new notes.
See commit 3c9b01f (16 Nov 2022) by Michael J Gruber (mjg
).
(Merged by Junio C Hamano -- gitster
-- in commit 2fe427e, 23 Nov 2022)
notes
: avoid empty line in templateSigned-off-by: Michael J Gruber
Signed-off-by: Taylor Blau
When
git notes
(man) prepares the template it adds an empty newline between the comment header and the content:# # Write/edit the notes for the following object: # commit 0f3c55d # etc
This is wrong structurally because that newline is part of the comment, too, and thus should be commented.
Also, it throws off some positioning strategies of editors and plugins, and it differs from how we do commit templates.Change this to follow the standard set by
git commit
(man):# # Write/edit the notes for the following object: # commit 0f3c55d
Tests pass unchanged after this code change.