I followed these instructions in order to merge Git notes.
I cloned a repo, added notes reference to the commit (refs/notes/commits
). When i push it, central repo rejects it as it was non-fast forward—because there was already a refs/notes/commits for that commit object. So in order to merge that remote Notes reference to my local Notes reference,
$ git checkout refs/notes/master
$ git fetch refs/notes/commits
$ git merge FETCH_HEAD
Auto-merging 206155715a78c9d91d42cda1de98449d2e0b1d36<br>
CONFLICT (add/add): Merge conflict in 206155715a78c9d91d42cda1de98449d........
Automatic merge failed; fix conflicts and then commit the result.
$ vi 206155715a78c9d91d42cda1de98449d........ [fix the conflict as usual manually]
$ git add 206155715a78c9d91d42cda1de98449d........
$ git commit -m "updated Notes"
[detached HEAD 0afb80f] changed notes
$ git update-ref refs/notes/commits HEAD
$ git checkout master <br>
Previous HEAD position was 0afb80f... changed notes
Switched to branch 'master'
$ git push origin refs/notes/commits
success
The question is, whether is this the best way to do this?
Following git notes man page, I tried the following.
$ git fetch refs/notes/commits
$ git notes merge -v refs/notes/commits
Nothing to Update!
The above steps obviously didn’t work for me. Is there a way to use the git notes merge command and merge the Notes, rather than the "branch method" as shown in the first illustration? For my uses, this straightforward command would be more helpful.
As I already alluded to in a comment, one reason the first approach is not working for you is that you copied the instructions wrong: your second step
git fetch refs/notes/commits
is missing the name of the remote.Regarding the second approach with
git notes merge
, again you have made the same mistake of missing the remote from thegit fetch
. But even with this fixed I struggled to get it to work until I finally figured out that you have to fetch the notes from the remote into a different ref namespace prior to merging, since if there is a conflict it won't let you overwrite what the localrefs/notes/commits
points to (although it will happily fast-forward it if there is no conflict).So this works for me:
If there are conflicts, it will now tell you to edit
.git/NOTES_MERGE_WORKTREE
and then commit the result viagit notes merge --commit
, or abort the merge withgit notes merge --abort
.One big disadvantage of using
git notes merge
over the technique suggested in the URL above is that the merge does not provide any index, so you can't use your normal merging workflow viagit mergetool
etc. Another is that it doesn't support rebasing. So if you expect complicated conflicts or need to rebase then I'd recommend going with thegit checkout refs/notes/commits
approach. But in the simple case,git notes merge
is probably more convenient because you can perform the merge whilst your working tree is dirty, whereasgit checkout refs/notes/commits
requires it to be clean.I'm pretty sure that the
git-notes(1)
man page could make this all a lot more obvious. Maybe I'll find some time to submit a patch for that. In the mean time however, I've written a new wrapper calledgit-rnotes
which makes it easier to share notes to and from remote repositories.