3

I'm trying to use git notes to store some (small) blobs of data. I almost have it working, but I'm having trouble when I try to fetch the data to another machine.

I'm using git hash-object and storing the returned hash in the note.

git hash-object -w timestamp.signed.tsr | git notes --ref=timestamps add --file -

I can push and fetch the notes that contain the hashes using the method outlined in Note to Self.

git push origin refs/notes/timestamps
git fetch origin refs/notes/*:refs/notes/*

However, I can't figure out how to get the blob objects to go along with it. I'm fairly certain my blob objects aren't getting pushed to origin. The way I'm checking is after pushing a note of 0dd470d2fc5556de62d813537fd483aede2f6b35, which should be the hash of a blob object, I go to the machine with my bare repository and look for objects/0d/d470d2fc5556de62d813537fd483aede2f6b35. Since it's not there, I assume it's never getting pushed.

Is there something simple I'm overlooking that I need to do so git knows the blob objects are referenced by the notes? Would it be better to store the data directly in the note? Would it be better to base64 encode the data and store it directly in the note?

Any tips would be appreciated.

Ryan J
  • 2,502
  • 5
  • 31
  • 41

1 Answers1

3

Notes can contain arbitrary data, they are not required or even expected to contain references to other objects. For that reason git will not interpret note contents as references. Since the commands that you have shown would not create an references to your hashed object, that object would not be pushed to a different repository. In fact the object would be eligible for garbage collection once it becomes old enough.

qqx
  • 18,947
  • 4
  • 64
  • 68
  • As a follow on, you will need to create a tag (or branch, but that's likely to cause confusion) that points to the object of interest, so that `git` doesn't see the object as orphaned, and so that it can be a candidate for `push`/`fetch`. – twalberg Dec 03 '12 at 16:07
  • That makes sense since I never was able to find an easy way to get it to work the way I was asking about in the question. I ended up base64 encoding the data and putting the data directly into git notes. [Here](http://codereview.stackexchange.com/questions/15380/am-i-making-any-beginner-errors-in-the-bash-script-for-adding-trusted-timestamps) is the script I ended up using and it seems to be working ok so far. – Ryan J Dec 03 '12 at 19:24