Given a commit with notes attached, can I take the message in the note and merge it into the commit's message when I do a rebase?
The background of this question is that I have a large repository imported via git-tfs that has a huge amount of notes linked to individual commits and while I am cleaning up the repository I would like to resolve the notes and merge them into the corresponding commit's messages.
Not currently, no. There's no fundamental reason it could not be done, but the support for notes-on-commits is still kind of primitive. Rebase can now copy a note when it copies a commit, but it does not offer the ability to squash notes when using squash.
If you want to implement this yourself, you should start with how
git notesactually work, which I'll describe here rather briefly. Git stores an auxiliary commit under the ref namerefs/notes/commits. This commit contains a series of files with weird-looking names, such as:for example. If you take the slashes out of the file name, the result is a hash ID. The contents of this file are the note for commit
5d01301f2b865aa8dba1654d3f447ce9d21db0b5.To update notes, or add new notes, Git will:
refs/notes/commitscommit; andrefs/notes/commitsto store the hash ID of the new commit.In effect, this is a lot like checking out the
refs/notes/commitscommit as a branch, except that you can't do that sincerefs/notes/commitsis not a branch name. (Also, Git uses a bunch of shortcuts here to avoid populating a full working tree.)Hence, to merge the notes of commits C1 and C2 that have been squashed into new commit C3, you would:
xx/xx/xx/xxto use (this varies: the notes code adds another layer whenever the tree gets "too crowded" at any given level; the actual level is implicit in the file names, but if you never split or join the names you don't have to worry about this);refs/notes/commitcommit, then updaterefs/notes/committo store the new commit's hash ID.You've now updated the notes for commit C3, so that when
git loggoes to show commit C3, if it's also showing notes, it will read the for-C3 file in your new commit.