As we saw in the previous example, we can add notes to the commits, but in some cases, it makes sense to store the information sorted by categories, such as featureImplemented
, defect
, and alsoCherryPick
. As briefly explained at the beginning of the chapter, notes are stored in refs/notes/commits
but we can add multiple references so that we can easily sort and list the different scopes of the notes.
To start this example, we need a new branch that tracks the origin/stable-3.1
branch; we name the branch notesReferences
, and create and checkout the branch with the following command:
$ git checkout -b notesReferences --track origin/stable-3.1 Branch notesReferences set up to track remote branch stable-3.1 from origin. Switched to a new branch 'notesReferences'
Imagine a situation where we have corrected a defect and did everything we could to ensure the quality of the commit before releasing it. Nonetheless, we had to make another fix for the same defect.
So, we want to add a note to the reference refs/notes/alsoCherryPick
, which should indicate that if you cherry pick this commit, you should also cherry pick the other commits as they fix the same defect.
In this example, we will find a commit and add some extra information to the commit in multiple notes' reference specifications:
$ git log -10 --oneline da6e87b Prepare post 3.1.0 builds 16ca725 JGit v3.1.0.201310021548-r c6aba99 Fix order of commits in rebase todo file header 5a2a222 Prepare post 3.1.0 RC1 builds 6f0681e JGit v3.1.0.201309270735-rc1 a065a06 Attempt to fix graph layout when new heads are introduced b4f07df Prepare re-signing pgm's ueberjar to avoid SecurityException aa4bbc6 Use full branch name when getting ref in BranchTrackingStatus 570bba5 Ignore bitmap indexes that do not match the pack checksum 801aac5 Merge branch 'stable-3.0'
b4f07df
commit in the ref alsoCherryPick
, we must use the --ref
option for git notes
. This has to be specified before the add
option:$ git notes --ref alsoCherryPick add -m "570bba5" b4f07df
git log -1
command. However, this is not the case. You actually need to specify that you want to list the notes from the specific ref. This can be done with the --notes=alsoCherryPick
option for git log
:$ git log -1 b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a --notes=alsoCherryPick commit b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a Author: Matthias Sohn <[email protected]> Date: Tue Sep 24 09:11:47 2013 +0200 Prepare re-signing pgm's ueberjar to avoid SecurityException More output... Change-Id: Ia302e68a4b2a9399cb18025274574e31d3d3e407 Signed-off-by: Matthias Sohn <[email protected]> Notes (alsoCherryPick): 570bba5
alsoCherryPick
notes. The reason for not showing is that Git defaults to adding notes into refs/notes/commits
. It would be nice if you could just show the alsoCherryPick
notes' reference by default. This can be done by configuring Git as follows:$ git config notes.displayRef "refs/notes/alsoCherryPick"
refs/notes/commits
notes? We can check this with git log -1
to see if we still have the test note displayed:$ git log -1 commit da6e87bc373c54c1cda8ed563f41f65df52bacbf Author: Matthias Sohn <[email protected]> Date: Thu Oct 3 17:22:08 2013 +0200 Prepare post 3.1.0 builds Change-Id: I306a3d40c6ddb88a16d17f09a60e3d19b0716962 Signed-off-by: Matthias Sohn <[email protected]> Notes: test note
notes.displayRef
configurations as we want, we should add all the refs we want to use in our repo. In some situations, it is even better to just add refs/notes/*
. This will configure Git to show all the notes:$ git config notes.displayRef 'refs/notes/*'
refs/notes/defect
now, we should be able to list it without specifying which notes' reference we want to list when using git log
. We are adding to the commit that already has a note in the alsoCherryPick
reference:$ git notes --ref defect add -m "Bug:24435" b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a
git log
:$ git log -1 b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a commit b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a Author: Matthias Sohn <[email protected]> Date: Tue Sep 24 09:11:47 2013 +0200 Prepare re-signing pgm's ueberjar to avoid SecurityException See http://dev.eclipse.org/mhonarc/lists/jgit-dev/msg02277.html Change-Id: Ia302e68a4b2a9399cb18025274574e31d3d3e407 Signed-off-by: Matthias Sohn <[email protected]> Notes (alsoCherryPick): 570bba5 Notes (defect): Bug:24435
I have been writing about the refs/notes/alsoCherryPick
reference and so on. As you know, we refer to the remote branches as references such as refs/remotes/origin/stable-3.2
, but the local branches are also references such as refs/heads/develop for instance
.
Since you can create a branch that starts at a specific reference, you should be able to create a branch that starts at the refs/notes/alsoCherrypick
reference:
refs/notes/alsoCherryPick
. Also, checkout the branch:$ git checkout -b myNotes notes/alsoCherryPick Switched to a new branch 'myNotes'
myNotes
branch now points to HEAD
on refs/notes/alsoCherryPick
. Listing the files on the branch will show a file with the commit hash of the commit we have added the notes to:$ ls b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a
$ cat b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a 570bba5
570bba5
we added as a note for b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a
is in the file. If we had a longer message, that message would also be shown here.