Attaching additional notes to a Git commit
When you commit a change in Git, you can add a message along with it. This message is essentially a note that you can add to the commit.
However, sometimes, you may want to add additional notes to the commit to add more context to it. For instance, recently, I deleted a file and committed the change with the message “deleted a file”. However, I wanted to add more context to the commit and add a note that the file was deleted because it was no longer needed.
Git allows you to add additional notes to an existing commit. You can do so by using the
git notes command. For instance, you can add a note to a commit by specifying its ID like so.
$ git notes add -m "Deleted script.html because it was no longer needed" f0a40dfff6582a516dd47d4bde8831b45e4ec40d
Now, when you run the
git log command, you’ll see the note added to the commit in addition to the commit message like so.
➜ test git:(master) git log commit f0a40dfff6582a516dd47d4bde8831b45e4ec40d (HEAD -> master) Author: Amit Merchant <[email protected]> Date: Sun Jan 1 18:48:30 2023 +0530 deleted a file Notes: Deleted script.html because it was no longer needed
Here’s a screenshot of the same.
Update a note
In any case, if you want to update the note, you can do so by adding the
-f option to the
git notes add command like so.
git notes add -f -m "Version 2 of the note" f0a40dfff6582a516dd47d4bde8831b45e4ec40d
👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!