Is more information always better? In some cases, yes, more information can be a big help, especially when working on a large project with other contributors. When it comes to working with Git, it is considered a best practice to leave short, terse commit messages, typically on one line. But what if you need to add some additional information that might be helpful? Git notes are a terrific way to add additional information about a commit to your Git project.
For developers or sysadmins experienced with the command line, get high availability and root access for your application, service, and websites with Cloud VPS Hosting.
As always, when creating or changing any elements of a Git project, you will want to make sure that the maintainers of the project are aware of any changes you are making. Some projects may have established rules and practices for how to write commits, whether or not to add notes, and other aspects of managing the Git workflow. Always make sure that you have at least checked to see how other contributors are using these features. And remember, if you want to host your own Git repositories you will need at least a cloud server VPS or managed VPS hosting.
How to Add Git Notes to a Commit
You can easily add a Git note at any point in the process of working on your project by running the following command:
git notes add
After running this command you will be prompted by text editor of your choice to type in the note message you wish to attach to the previous commit.
By default, this command attaches the note to the most recent commit or at the point of the HEAD reference marker.
To add a note to a previous commit you can use the “edit” option and part of a commit hash or some other reference to the object:
git notes edit <object>
How to View Git Notes In the Git Log
As always with Git, there are many different ways to do the same thing. For going back to peruse your notes that you have attached to various commits, the easiest way to get going is to use the
git log command:
Here is a sample log entry you will see when running the
git log command with no options.
commit 0l4d49e9fj82f21267f9fb857fj237sdf442c1eae (HEAD -> testing, origin/testing) Author: Joe Example <[email protected]> Date: Wed Nov 10 10:19:11 2021 -0500 This is the commit message. Notes: This is a test note.
Well done! You now know how to use Git notes to provide additional information to a commit. Where will your Git journey take you next? Looking for an alternative to GitHub? Why not create your own Git server?