{"thread":{"id":"62191","subject":"Can a note be pushed to origin?","startedAt":"2024-09-25T12:25:17Z","lastAt":"2024-09-28T09:53:06Z","messageCount":4,"participants":["Stephen P. Smith","Kristoffer Haugsbakk","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"503464","messageId":"20240925122515.14015-1-ishchis2@gmail.com","threadId":"62191","inReplyTo":null,"subject":"Can a note be pushed to origin?","fromName":"Stephen P. Smith","fromEmail":"ishchis2@gmail.com","sentAt":"2024-09-25T12:25:15Z","receivedAt":"2024-09-25T12:25:17Z","isPatch":false,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"In a project that I am working on, some metadata is currently embedded in some \nsource files.  The question was asked yesterday if there is a way to move that \nmetadata a git specific file and link it to the source file or commit.\n\nI remembered that git has notes which can be used to add such data to a \ncommit, but I don't believe that such metadata gets pushed to origin nor \nfetched from origin but another user.  \n\nIs there a currently implemented way to do something like this?\n"},{"id":"503472","messageId":"6b69af87-9002-46a7-a5f3-3fa1fb7ba9df@app.fastmail.com","threadId":"62191","inReplyTo":"20240925122515.14015-1-ishchis2@gmail.com","subject":"Re: Can a note be pushed to origin?","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2024-09-25T15:29:30Z","receivedAt":"2024-09-25T15:29:51Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"Hi\n\nOn Wed, Sep 25, 2024, at 14:25, Stephen P. Smith wrote:\n> In a project that I am working on, some metadata is currently embedded in some\n> source files.  The question was asked yesterday if there is a way to move that\n> metadata a git specific file and link it to the source file or commit.\n>\n> I remembered that git has notes which can be used to add such data to a\n> commit, but I don't believe that such metadata gets pushed to origin nor\n> fetched from origin but another user.\n>\n> Is there a currently implemented way to do something like this?\n\nYou have to do it manually.\n\nIn `.git/config`:\n\n```\n[remote \"origin\"]\n\turl = <url>\n        […]\n\tfetch = refs/notes/commits:refs/notes/commits\n```\n\nThat fetches the default Notes ref on `git fetch origin`.\n\nThat will refuse to update if your own notes ever diverge from the\nremote.  If you want to always overwrite your local notes with the\nremote ones:\n\n```\n[remote \"origin\"]\n\turl = <url>\n        […]\n\tfetch = +refs/notes/commits:refs/notes/commits\n```\n\nBut then you should also enable reflog updates for all refs:\n\n```\ngit config set --global core.logAllRefUpdates always\n```\n\nIn case you do a fetch that you want to undo.\n\n-- \nKristoffer Haugsbakk\n\n"},{"id":"503602","messageId":"20240927041516.GA568026@coredump.intra.peff.net","threadId":"62191","inReplyTo":"6b69af87-9002-46a7-a5f3-3fa1fb7ba9df@app.fastmail.com","subject":"Re: Can a note be pushed to origin?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-09-27T04:15:16Z","receivedAt":"2024-09-27T04:15:18Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 25, 2024 at 05:29:30PM +0200, Kristoffer Haugsbakk wrote:\n\n> That will refuse to update if your own notes ever diverge from the\n> remote.  If you want to always overwrite your local notes with the\n> remote ones:\n\nThere are some specialized strategies for merging notes (e.g., taking\nthe union of lines). See the \"merge\" subcommand in git-notes(1).\n\nI don't recall ever really using it myself, and I don't think there's\nreally any porcelain support, so you're on your own to invoke the merge.\nBut I guess the use case would be something like:\n\n  # fetch their notes into a holding spot\n  git config remote.origin.fetch refs/notes/commits:refs/notes/origin/commits\n\n  # and then after every fetch, you merge if necessary. By default we're\n  # merging into our own \"refs/notes/commits\". And it should be OK to\n  # use the short \"origin/commits\" here, since notes-refs have their own\n  # special lookup rules. Though using the fully qualified refname is\n  # probably reasonable, too.\n  git fetch\n  git notes merge -s union origin/commits\n\n-Peff\n"},{"id":"503629","messageId":"ca632f1a-c41f-42b3-8f8d-4ef32fe18e33@app.fastmail.com","threadId":"62191","inReplyTo":"20240927041516.GA568026@coredump.intra.peff.net","subject":"Re: Can a note be pushed to origin?","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2024-09-28T09:52:45Z","receivedAt":"2024-09-28T09:53:06Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Fri, Sep 27, 2024, at 06:15, Jeff King wrote:\n> On Wed, Sep 25, 2024 at 05:29:30PM +0200, Kristoffer Haugsbakk wrote:\n>\n>> That will refuse to update if your own notes ever diverge from the\n>> remote.  If you want to always overwrite your local notes with the\n>> remote ones:\n>\n> There are some specialized strategies for merging notes (e.g., taking\n> the union of lines). See the \"merge\" subcommand in git-notes(1).\n>\n> I don't recall ever really using it myself, and I don't think there's\n> really any porcelain support, so you're on your own to invoke the merge.\n> But I guess the use case would be something like:\n>\n>   # fetch their notes into a holding spot\n>   git config remote.origin.fetch refs/notes/commits:refs/notes/origin/commits\n>\n>   # and then after every fetch, you merge if necessary. By default we're\n>   # merging into our own \"refs/notes/commits\". And it should be OK to\n>   # use the short \"origin/commits\" here, since notes-refs have their own\n>   # special lookup rules. Though using the fully qualified refname is\n>   # probably reasonable, too.\n>   git fetch\n>   git notes merge -s union origin/commits\n\ngit-notes(1) feels like the most “plumbing” command out of the “main\nporcelain commands”. :) (of those that I use)\n\nFor my needs though it is high level enough since I mostly add notes to\nmy own commits. Certainly porcelain in that sense. I use it all the time\nto add testing/general comments to my commits.\n\n-- \nKristoffer Haugsbakk\n"}]}