Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Git notes to a blob

Tags:

git

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?

like image 224
maxmelbin Avatar asked Mar 23 '12 13:03

maxmelbin


People also ask

How do I add notes to git?

Notes can also be added to patches prepared with git format-patch by using the --notes option. Such notes are added as a patch commentary after a three dash separator line. To change which notes are shown by git log, see the "notes. displayRef" configuration in git-log[1].

What is a git blob?

A Git blob (binary large object) is the object type used to store the contents of each file in a repository. The file's SHA-1 hash is computed and stored in the blob object. These endpoints allow you to read and write blob objects to your Git database on GitHub. Blobs leverage these custom media types.

What does git add u do?

The git add command adds new or changed files in your working directory to the Git staging area. git add is an important command – without it, no git commit would ever do anything.

What is the push command in git?

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo.


1 Answers

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 the notes/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.

like image 156
VonC Avatar answered Oct 13 '22 21:10

VonC